Commit Graph

28 Commits

Author SHA1 Message Date
Anthony Sottile a49f812a96 py39+
Committed via https://github.com/asottile/all-repos
2024-10-11 19:30:07 -04:00
Anthony Sottile 8f6152921e drop python3.6 support
python 3.6 reached end of life on 2021-12-23

Committed via https://github.com/asottile/all-repos
2022-01-15 19:24:05 -05:00
Anthony Sottile 39ab2ed85e replace exit(main()) with raise SystemExit(main())
Committed via https://github.com/asottile/all-repos
2021-10-23 13:23:50 -04:00
Anthony Sottile 21553c2ca9 Allow arbitrarily encoded files to be checked with detect-aws-credentials 2020-02-18 10:24:17 -08:00
Alexander Demin b3a28deca7 Review fixes 2020-02-13 17:12:45 +00:00
Alexander Demin 75d4832e98 Unit test for empty AWS variables 2020-02-13 12:01:38 +00:00
Alexander Demin ace459bec5 Skip empty variables in detect_aws_credentials 2020-02-12 21:54:05 +00:00
Anthony Sottile f5c42a050b pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
Anthony Sottile 4575652bd2 Use default flake8 config 2019-02-11 19:56:15 -08:00
Anthony Sottile 030bfac7e4 Apply typing to all of pre-commit-hooks 2019-01-31 20:09:15 -08:00
Ryan Delaney 0d83fed4fa Reword usage info to clarify required usage syntax 2018-10-28 16:00:01 -07:00
Ryan Delaney 2d4833c73e Rename metavar to clarify required usage syntax 2018-10-28 15:58:14 -07:00
Pablo Vega 83fca4c614 Adding a check to make sure either spaces or null values are not mistakenly added into the key variable 2018-01-26 00:28:39 -08:00
Anthony Sottile 2a902e0a07 Use asottile/add-trailing-comma 2017-07-12 18:58:30 -07:00
Mike Fiedler 312e721ce9
Add flag to detect-aws-credentials to allow missing keys
In the event that there exists no configuration for AWS credentials and
they are not exported in to the current environment, a flag may be
passed to allow exiting the hook successfully.

Resolves #174

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2017-02-10 12:54:03 -05:00
Anthony Sottile 5da199bb8d Formatting fixups 2017-01-03 13:13:44 -08:00
Daniel Roschka 3939aee4a3 Address issues mentioned in review 2017-01-03 19:05:49 +01:00
Daniel Roschka 0fd09bf67a Add AWS_CONFIG_FILE to the environment variables
Turns out there is an additional environment variable AWS_CONFIG_FILE,
which gets evaluated for finding configuration files as well. This
commit adds support for it.
2016-12-30 10:39:38 +01:00
Daniel Roschka b0d4cdb1ee Improve searching for configured AWS credentials
The previous approach for finding AWS credentials was pretty naive and
only covered contents of a single file (~/.aws/credentials by
default).

The AWS CLI documentation states various other ways to configure
credentials which weren't covered:
https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#credentials
Even that aren't all ways, a look into the code shows:
https://github.com/boto/botocore/blob/develop/botocore/credentials.py

This commit changes the behavior so the hook will behave in a way
that if the AWS CLI is able to obtain credentials from local files,
the hook will find them as well.

The changes in detail are:
- detect AWS session tokens and handle them like secret keys.
- always search credentials in the default AWS CLI file locations
  ( ~/.aws/config, ~/.aws/credentials, /etc/boto.cfg and ~/.boto)
- detect AWS credentials configured via environment variables in
  AWS_SECRET_ACCESS_KEY, AWS_SECURITY_TOKEN and AWS_SESSION_TOKEN
- check additional configuration files configured via environment
  variables (AWS_CREDENTIAL_FILE, AWS_SHARED_CREDENTIALS_FILE and
  BOTO_CONFIG)
- print out the first four characters of each secret found in files to
  be checked in, to make it easier to figure out, what the secrets
  were, which were going to be checked in
- improve error handling for parsing ini-files
- improve tests

There is a major functional change introduced by this commit:
Locations the AWS CLI gets credentials from are always searched and
there is no way to disable them. --credentials-file is still there to
specify one or more additional files to search credentials in. It's
the purpose of this hook to find and check files for found
credentials, so it should work in any case. As this commit also
improves error handling for not-existing or malformed configuration
files, it should be no big deal.

Receiving credentials via the EC2 and ECS meta data services is not
covered intentionally, to not further increase the amount of changes
in this commit and as it's probably an edge case anyway to have this
hook running in such an environment.
2016-12-30 08:41:24 +01:00
Anthony Sottile 70e405ede2 Add a new hook to forbid new submodules 2016-11-30 09:56:42 -08:00
Anthony Sottile 8be6f4c77e Remove pylint 2016-08-22 14:38:49 -07:00
Anthony Sottile d444ab821d Improve error message when credentials file is not provided 2016-02-08 17:18:56 -08:00
Dean Wilson a6665279e7 Show names of files containing aws credentials 2015-10-28 05:13:37 +00:00
Ara Hayrabedian 974ef4e93c disable import checking for six.moves 2015-06-13 14:18:08 +04:00
Ara Hayrabedian 02e8bdc9d8 add tests, test sample files and minor refactor of exit codes in actual hook in order to facilitate testing 2015-06-12 19:20:56 +04:00
Ara Hayrabedian 88725503c4 remove print statement 2015-06-12 17:02:06 +04:00
Ara Hayrabedian 3078aec57b use six for config parser, add to reqs
ditch checkign access_key (don't consider these a secret)
don't check line by line, check the whole file in bulk instead
2015-06-12 16:24:01 +04:00
Ara Hayrabedian 95bf20d52d add aws credential checking ONLY FOR YOUR OWN credentials if they're set in a configurable credentials file (AWS CLI tools' native format) 2015-06-01 23:16:51 +04:00