Skip to content

Commit 4391f7a

Browse files
authored
Merge pull request #112 from britive/develop
v1.6.0rc3
2 parents 9e2c50c + 2e708d3 commit 4391f7a

File tree

5 files changed

+49
-14
lines changed

5 files changed

+49
-14
lines changed

CHANGELOG.md

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

33
* As of v1.4.0 release candidates will be published in an effort to get new features out faster while still allowing time for full QA testing before moving the release candidate to a full release.
44

5+
## v1.6.0rc3 [2023-10-31]
6+
#### What's New
7+
* None
8+
9+
#### Enhancements
10+
* None
11+
12+
#### Bug Fixes
13+
* Clarified language in an error message when an authentication token has been invalidated on the server side and the resulting action the user must take to clear the token.
14+
* More gracefully handle when a Kubernetes `certificate-authority-data` cannot be base64 decoded to a proper certificate - we will skip over that specific cluster.
15+
16+
#### Dependencies
17+
* None
18+
19+
#### Other
20+
* None
21+
22+
523
## v1.6.0rc2 [2023-10-27]
624
#### What's New
725
* None

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 1.6.0rc2
3+
version = 1.6.0rc3
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive

src/pybritive/britive_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,13 +1168,13 @@ def request_disposition(self, request_id, decision):
11681168

11691169
def clear_cached_aws_credentials(self, profile):
11701170
# start with the profile name that was passed in from the command
1171-
Cache().clear_awscredentialprocess(profile_name=profile)
1171+
Cache().clear_credentials(profile_name=profile)
11721172

11731173
# then we can try to split it into parts and clear that version of the
11741174
# profile name as well - it will not hurt anything to try to clear
11751175
# both versions
11761176
parts = self._split_profile_into_parts(profile)
1177-
Cache().clear_awscredentialprocess(profile_name=f"{parts['app']}/{parts['env']}/{parts['profile']}")
1177+
Cache().clear_credentials(profile_name=f"{parts['app']}/{parts['env']}/{parts['profile']}")
11781178

11791179
def ssh_gcp_identity_aware_proxy(self, username, hostname, push_public_key, port_number, key_source):
11801180
self.silent = True

src/pybritive/cli_interface.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ def safe_cli():
2525
sys.tracebacklimit = 0
2626
cli()
2727
except Exception as e:
28-
part1 = '401 - e0000 - aws access token for subject'
29-
part2 = 'not authorized by cognito'
30-
if part1 in str(e).lower() and part2 in str(e).lower():
31-
click.echo('You have logged out of Britive via the browser. Please run `pybritive logout` to clear your '
28+
if '401 - e0000' in str(e).lower():
29+
click.echo('You have logged out of Britive via the browser. Please run '
30+
'`pybritive logout [-t/--tenant <tenant>]` to clear your '
3231
'token and then re-run your command.')
3332
return
3433
if debug:

src/pybritive/helpers/kube_config_builder.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import click
12
import yaml
23
from pathlib import Path
34
from .config import ConfigManager
45
from ..britive_cli import BritiveCli
56
import os
7+
import base64
68

79

810
def sanitize(name: str):
@@ -32,7 +34,7 @@ def check_env_var(filename, cli: BritiveCli):
3234
cli.print(command)
3335

3436

35-
def merge_new_with_existing(clusters, contexts, users, filename, tenant, assigned_aliases):
37+
def merge_new_with_existing(clusters, contexts, users, filename, tenant):
3638
# get the existing config, so we can pop out all
3739
# items related to this tenant as we will be replacing
3840
# them with the above created items
@@ -47,8 +49,8 @@ def merge_new_with_existing(clusters, contexts, users, filename, tenant, assigne
4749
clusters.append(cluster)
4850

4951
for context in existing_kubeconfig.get('contexts', []):
50-
name = context.get('name', '')
51-
if not name.startswith(prefix) and name not in assigned_aliases:
52+
cluster_name = context.get('context', {}).get('cluster', '')
53+
if not cluster_name.startswith(prefix):
5254
contexts.append(context)
5355

5456
for user in existing_kubeconfig.get('users', []):
@@ -94,7 +96,20 @@ def parse_profiles(profiles, aliases):
9496
return [cluster_names, assigned_aliases]
9597

9698

97-
def build_tenant_config(tenant, cluster_names, username):
99+
def valid_cert(cert: str, profile: str, cli: BritiveCli):
100+
try:
101+
decoded_cert = base64.b64decode(cert).decode('utf-8')
102+
if not decoded_cert.startswith('-----BEGIN CERTIFICATE-----'):
103+
raise ValueError()
104+
if not decoded_cert.strip().endswith('-----END CERTIFICATE-----'):
105+
raise ValueError()
106+
return True
107+
except Exception:
108+
cli.print(f'could not properly decode certificate authority data for profile {profile} - skipping this cluster')
109+
return False
110+
111+
112+
def build_tenant_config(tenant, cluster_names, username, cli: BritiveCli):
98113
users = [
99114
{
100115
'name': username,
@@ -125,6 +140,9 @@ def build_tenant_config(tenant, cluster_names, username):
125140
cert = details['cert']
126141
url = details['url']
127142

143+
if not valid_cert(cert=cert, profile=details['profile'], cli=cli):
144+
continue
145+
128146
for name in names:
129147
clusters.append(
130148
{
@@ -173,7 +191,8 @@ def build_kube_config(profiles: list, config: ConfigManager, username: str, cli:
173191
clusters, contexts, users = build_tenant_config(
174192
tenant=tenant,
175193
cluster_names=cluster_names,
176-
username=username
194+
username=username,
195+
cli=cli
177196
)
178197

179198
# calculate the path for the config
@@ -188,8 +207,7 @@ def build_kube_config(profiles: list, config: ConfigManager, username: str, cli:
188207
contexts=contexts,
189208
users=users,
190209
tenant=tenant,
191-
filename=filename,
192-
assigned_aliases=assigned_aliases
210+
filename=filename
193211
)
194212

195213
# if required ensure we tell the user they need to modify their KUBECONFIG env var

0 commit comments

Comments
 (0)