Skip to content

Commit 36d5991

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 695f69a + acd8854 commit 36d5991

20 files changed

+2583
-1502
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ matrix:
55
include:
66
- python: '3.6'
77
env: TOXENV=py36 VAULT_BRANCH=release RELEASE=yes
8+
- python: '3.6'
9+
env: TOXENV=py36-flake8 VAULT_BRANCH=release RELEASE=yes
810
- python: '3.6'
911
env: TOXENV=py36 VAULT_BRANCH=head
1012
allow_failures:

CHANGELOG.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
# Changelog
2+
3+
## 0.6.0 (June 14, 2018)
4+
5+
BACKWARDS COMPATIBILITY NOTICE:
6+
7+
* Token revocation now sends the token in the request payload. Requires Vault >0.6.5
8+
* Various methods have new and/or re-ordered keyword arguments. Code calling these methods with positional arguments
9+
may need to be modified.
10+
11+
IMPROVEMENTS:
12+
13+
* Ensure mount_point Parameter for All AWS EC2 Methods [GH-195]
14+
* Add Methods for Auth Backend Tuning [GH-193]
15+
* Customizable approle path / mount_point [GH-190]
16+
* Add more methods for the userpass backend [GH-175]
17+
* Add transit signature_algorithm parameter [GH-174]
18+
* Add auth_iam_aws() method [GH-170]
19+
* lookup_token function POST token not GET [GH-164]
20+
* Create_role_secret_id with wrap_ttl & fix get_role_secret_id_accessor [GH-159]
21+
* Fixed json() from dict bug and added additional arguments on auth_ec2() method [GH-157]
22+
* Support specifying period when creating EC2 roles [GH-140]
23+
* Added support for /sys/generate-root endpoint [GH-131] / [GH-199]
24+
* Added "auth_cubbyhole" method [GH-119]
25+
* Send token/accessor as a payload to avoid being logged [GH-117]
26+
* Add AppRole delete_role method [GH-112]
27+
28+
29+
BUG FIXES:
30+
31+
* Always Specify auth_type In create_ec2_role [GH-197]
32+
* Fix "double parasing" of JSON response in auth_ec2 method [GH-181]
33+
34+
Thanks to @freimer, @ramiamar, @marcoslopes, @ianwestcott, @marc-sensenich, @sunghyun-lee, @jnaulty, @sijis,
35+
@Myles-Steinhauser-Bose, @oxmane, @ltm, @bchannak, @tkinz27, @crmulliner, for their lovely contributions.
36+
37+
## 0.5.0 (February 20, 2018)
38+
39+
IMPROVEMENTS:
40+
41+
* Added `disallowed_policies` parameter to `create_token_role` method [GH-169]
42+
43+
Thanks to @morganda for their lovely contribution.
44+
145
## 0.4.0 (February 1, 2018)
246

347
IMPROVEMENTS:
@@ -9,7 +53,7 @@ BUG FIXES:
953

1054
* Documentation is now more accurate [GH-165] / [GH-154]
1155

12-
Thanks to @ti-mo, @dhoeric, @RAbraham, @lhdumittan, @ahsanali for
56+
Thanks to @ti-mo, @dhoeric, @RAbraham, @lhdumittan, @ahsanali for
1357
their lovely contributions.
1458

1559
## 0.3.0 (November 9, 2017)

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ await client.auth_app_id('MY_APP_ID', 'MY_USER_ID')
6161
# App Role
6262
await client.auth_approle('MY_ROLE_ID', 'MY_SECRET_ID')
6363

64+
# AWS (IAM)
65+
client.auth_aws_iam('MY_AWS_ACCESS_KEY_ID', 'MY_AWS_SECRET_ACCESS_KEY')
66+
client.auth_aws_iam('MY_AWS_ACCESS_KEY_ID', 'MY_AWS_SECRET_ACCESS_KEY', 'MY_AWS_SESSION_TOKEN')
67+
client.auth_aws_iam('MY_AWS_ACCESS_KEY_ID', 'MY_AWS_SECRET_ACCESS_KEY', role='MY_ROLE')
68+
69+
import boto3
70+
session = boto3.Session()
71+
credentials = session.get_credentials()
72+
client.auth_aws_iam(credentials.access_key, credentials.secret_key, credentials.token)
73+
6474
# GitHub
6575
await client.auth_github('MY_GITHUB_TOKEN')
6676

@@ -228,8 +238,9 @@ print(await client.is_sealed()) # => True
228238
Integration tests will automatically start a Vault server in the background. Just make sure
229239
the latest `vault` binary is available in your `PATH`.
230240

231-
1. [Install Vault](https://vaultproject.io/docs/install/index.html)
241+
1. [Install Vault](https://vaultproject.io/docs/install/index.html) or execute `VAULT_BRANCH=release scripts/install-vault-release.sh`
232242
2. [Install Tox](http://tox.readthedocs.org/en/latest/install.html)
243+
3. Run tests: `make test`
233244

234245
## Contributing
235246

async_hvac/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
from async_hvac.v1 import Client
2-
from async_hvac.v1 import async_to_sync
1+
from async_hvac.v1 import AsyncClient
2+
# assert for flake8's sake
3+
assert AsyncClient

async_hvac/aws_utils.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import hmac
2+
from datetime import datetime
3+
from hashlib import sha256
4+
5+
6+
class SigV4Auth(object):
7+
def __init__(self, access_key, secret_key, session_token=None):
8+
self.access_key = access_key
9+
self.secret_key = secret_key
10+
self.session_token = session_token
11+
12+
def add_auth(self, method, headers, body):
13+
if body:
14+
headers['Content-Length'] = str(len(body))
15+
timestamp = datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')
16+
headers['X-Amz-Date'] = timestamp
17+
18+
if self.session_token:
19+
headers['X-Amz-Security-Token'] = self.session_token
20+
21+
# https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
22+
canonical_headers = ''.join('{0}:{1}\n'.format(k.lower(), headers[k]) for k in sorted(headers))
23+
signed_headers = ';'.join(k.lower() for k in sorted(headers))
24+
payload_hash = sha256(body.encode('utf-8')).hexdigest()
25+
canonical_request = '\n'.join([method, '/', '', canonical_headers, signed_headers, payload_hash])
26+
27+
# https://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html
28+
algorithm = 'AWS4-HMAC-SHA256'
29+
credential_scope = '/'.join([timestamp[0:8], 'us-east-1', 'sts', 'aws4_request'])
30+
canonical_request_hash = sha256(canonical_request.encode('utf-8')).hexdigest()
31+
string_to_sign = '\n'.join([algorithm, timestamp, credential_scope, canonical_request_hash])
32+
33+
# https://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
34+
key = 'AWS4{0}'.format(self.secret_key).encode('utf-8')
35+
key = hmac.new(key, timestamp[0:8].encode('utf-8'), sha256).digest()
36+
key = hmac.new(key, 'us-east-1'.encode('utf-8'), sha256).digest()
37+
key = hmac.new(key, 'sts'.encode('utf-8'), sha256).digest()
38+
key = hmac.new(key, 'aws4_request'.encode('utf-8'), sha256).digest()
39+
signature = hmac.new(key, string_to_sign.encode('utf-8'), sha256).hexdigest()
40+
41+
# https://docs.aws.amazon.com/general/latest/gr/sigv4-add-signature-to-request.html
42+
authorization = '{0} Credential={1}/{2}, SignedHeaders={3}, Signature={4}'.format(
43+
algorithm, self.access_key, credential_scope, signed_headers, signature)
44+
headers['Authorization'] = authorization

async_hvac/exceptions.py

+9
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,38 @@ def __init__(self, message=None, errors=None):
77

88
super(VaultError, self).__init__(message)
99

10+
1011
class InvalidRequest(VaultError):
1112
pass
1213

14+
1315
class Unauthorized(VaultError):
1416
pass
1517

18+
1619
class Forbidden(VaultError):
1720
pass
1821

22+
1923
class InvalidPath(VaultError):
2024
pass
2125

26+
2227
class RateLimitExceeded(VaultError):
2328
pass
2429

30+
2531
class InternalServerError(VaultError):
2632
pass
2733

34+
2835
class VaultNotInitialized(VaultError):
2936
pass
3037

38+
3139
class VaultDown(VaultError):
3240
pass
3341

42+
3443
class UnexpectedError(VaultError):
3544
pass

0 commit comments

Comments
 (0)