Skip to content

Commit ca97473

Browse files
authored
Merge pull request #42 from britive/develop
v0.7.2
2 parents 5a8ecfe + cc226bc commit ca97473

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
All changes to the package starting with v0.3.1 will be logged here.
44

5+
## v0.7.2 [2022-12-12]
6+
#### What's New
7+
* None
8+
9+
#### Enhancements
10+
* None
11+
12+
#### Bug Fixes
13+
* None
14+
15+
#### Dependencies
16+
* `britive~=2.12.3` from `britive~=2.12.2` - AWS provider tenant port removal, disable SSL verification, json decode bug fix
17+
18+
#### Other
19+
* None
20+
521
## v0.7.1 [2022-11-28]
622
#### What's New
723
* None

docs/index.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,58 @@ order of operations for determining the tenant.
6767
## Credential Selection Logic
6868

6969
There are numerous ways to provide the CLI with the Britive credentials that should be used to authenticate to the
70-
Britive tenant. The below list is the order of operations for determining the tenant.
70+
Britive tenant. The below list is the order of operations for determining the token to use.
7171

72-
1. Value retrieved from CLI option/flag `--token/-T`
73-
2. Value retrieved from environment variable `BRITIVE_API_TOKEN`
74-
3. If none of the above are available an interactive login will be performed and temporary credentials will be stored locally for future use with the CLI
72+
1. Workload federation provider token via option/flag `--federation-provider/-P` (see below for more details on this option)
73+
2. Value retrieved from CLI option/flag `--token/-T`
74+
3. Value retrieved from environment variable `BRITIVE_API_TOKEN`
75+
4. If none of the above are available an interactive login will be performed and temporary credentials will be stored locally for future use with the CLI
7576

7677

78+
## Workload Federation Providers
79+
80+
*NOTE*: Before any of the below will work there is required setup and configuration within your Britive tenant
81+
so trust can be established between the identity provider and Britive.
82+
83+
`pybritive` and the Python SDK offer the capability to source an ephemeral token from a federation provider.
84+
This use case is targeted for machines/automated workloads and removes the need to store a long-lived API token
85+
to interact with Britive. These tokens are mapped to service identities within your Britive tenant.
86+
87+
At feature launch the following types of identity providers are supported for workload identity federation.
88+
89+
* Open ID Connect (OIDC)
90+
* AWS STS
91+
92+
`pybritive` offers some native integrations with the following services at the launch of this feature.
93+
94+
* Github Actions
95+
* AWS
96+
97+
It is possible to source an identity token from a different OIDC provider and explicitly set it via the `--token\-T` flag.
98+
However, if you are using one of the above providers, a shortcut is provided to abstract away the complexity of sourcing these tokens.
99+
Over time this list will grow. Reach out to your customer success manager if you have an identity provider you would like added to
100+
this list.
101+
102+
A couple of examples are below which illustrate how to use the above identity providers. Note that these commands will only work
103+
if they are being run within the context of the identity provider. Otherwise, the necessary data and connections will not be
104+
present in the execution environment.
105+
106+
~~~bash
107+
# github actions
108+
pybritive checkout "profile" --federation-provider github # use github actions with the default OIDC audience
109+
pybritive checkout "profile" --federation-provider github-audience # use github actions with a custom OIDC audience
110+
pybritive checkout "profile" --federation-provider github-audience_expirationseconds # use github actions with a custom OIDC audience and set the Britive expiration (in seconds) of the generated token
111+
pybritive checkout "profile" --federation-provider github_expirationseconds # use github actions with the default OIDC audience and set the Britive expiration (in seconds) of the generated token
112+
113+
# aws sts
114+
pybritive checkout "profile" --federation-provider aws # use aws sts without an AWS CLI profile (source credentials via the standard credential discovery process)
115+
pybritive checkout "profile" --federation-provider aws-profile # use aws sts with an AWS CLI profile
116+
pybritive checkout "profile" --federation-provider aws-profile_expirationseconds # use aws sts with an AWS CLI profile and set the Britive expiration (in seconds) of the generated token
117+
pybritive checkout "profile" --federation-provider aws_expirationseconds # use aws sts without an AWS CLI profile and set the Britive expiration (in seconds) of the generated token
118+
~~~
119+
120+
In general the field format for `--federation-provider` is `provider-[something provider specific]_[duration in seconds]`.
121+
77122
## Credential Stores
78123

79124
The CLI currently offers two ways in which temporary credentials obtained via interactive login can be stored.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
britive~=2.12.2
1+
britive~=2.12.3
22
certifi==2022.6.15
33
charset-normalizer==2.1.0
44
click==8.1.3

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 0.7.1
3+
version = 0.7.2
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive
@@ -26,7 +26,7 @@ install_requires =
2626
toml
2727
cryptography
2828
python-dateutil
29-
britive>=2.12.2
29+
britive>=2.12.3
3030

3131
[options.packages.find]
3232
where = src

src/pybritive/helpers/credentials.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import webbrowser
66
import requests
7+
from requests.adapters import HTTPAdapter, Retry
78
from pathlib import Path
89
import click
910
import configparser
@@ -50,6 +51,7 @@ def __init__(self, tenant_name: str, tenant_alias: str, cli: any, federation_pro
5051
self.alias = tenant_alias
5152
self.base_url = f'https://{Britive.parse_tenant(tenant_name)}'
5253
self.federation_provider = federation_provider
54+
self.session = None
5355

5456
# not sure if we really need 32 random bytes or if any random string would work
5557
# but the current britive-cli in node.js does it this way so it will be done the same
@@ -58,10 +60,29 @@ def __init__(self, tenant_name: str, tenant_alias: str, cli: any, federation_pro
5860
self.auth_token = b64_encode_url_safe(bytes(hashlib.sha512(self.verifier.encode('utf-8')).digest()))
5961
self.credentials = self.load() or {}
6062

63+
def _setup_requests_session(self):
64+
self.session = requests.Session()
65+
retries = Retry(total=5, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504])
66+
self.session.mount('https://', HTTPAdapter(max_retries=retries))
67+
68+
# allow the disabling of TLS/SSL verification for testing in development (mostly local development)
69+
if os.getenv('BRITIVE_NO_VERIFY_SSL') and '.dev.' in self.tenant:
70+
# turn off ssl verification
71+
self.session.verify = False
72+
# wipe these due to this bug: https://github.com/psf/requests/issues/3829
73+
os.environ['CURL_CA_BUNDLE'] = ""
74+
os.environ['REQUESTS_CA_BUNDLE'] = ""
75+
# disable the warning message
76+
import urllib3
77+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
78+
6179
def perform_interactive_login(self):
6280
self.cli.print(f'Performing interactive login against tenant {self.tenant}.')
6381
url = f'{self.base_url}/login?token={self.auth_token}'
6482

83+
# establish a requests session which will be used in retrieve_tokens()
84+
self._setup_requests_session()
85+
6586
try:
6687
webbrowser.get()
6788
webbrowser.open(url)

0 commit comments

Comments
 (0)