csaccess 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- csaccess/__init__.py +396 -0
- csaccess/__main__.py +21 -0
- csaccess/constants.py +35 -0
- csaccess/rp.py +193 -0
- csaccess/utils.py +70 -0
- csaccess-0.0.1.dist-info/METADATA +333 -0
- csaccess-0.0.1.dist-info/RECORD +11 -0
- csaccess-0.0.1.dist-info/WHEEL +5 -0
- csaccess-0.0.1.dist-info/entry_points.txt +2 -0
- csaccess-0.0.1.dist-info/licenses/LICENSE +176 -0
- csaccess-0.0.1.dist-info/top_level.txt +1 -0
csaccess/__init__.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
# -*- mode: python; coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 CONTACT Software GmbH
|
|
4
|
+
# https://www.contact-software.com/
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import functools
|
|
20
|
+
import getpass
|
|
21
|
+
import json
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
import sys
|
|
25
|
+
import time
|
|
26
|
+
import urllib.request
|
|
27
|
+
import urllib.parse
|
|
28
|
+
import webbrowser
|
|
29
|
+
|
|
30
|
+
import boto3
|
|
31
|
+
|
|
32
|
+
from typing import Callable, Dict, Optional, Any
|
|
33
|
+
|
|
34
|
+
from csaccess.utils import mask_sensitive_data
|
|
35
|
+
from csaccess.rp import RPServer
|
|
36
|
+
from csaccess.constants import DEFAULT_CONFIG
|
|
37
|
+
|
|
38
|
+
logger = logging.getLogger(__name__)
|
|
39
|
+
|
|
40
|
+
# Type alias for action functions, for clarity.
|
|
41
|
+
ActionFunction = Callable[[argparse.Namespace], Optional[str]]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@functools.lru_cache(maxsize=1)
|
|
45
|
+
def get_issuer_config(oidc_issuer: str) -> Dict[str, Any]:
|
|
46
|
+
"""Retrieve and cache the OIDC issuer configuration."""
|
|
47
|
+
logger.debug("get_issuer_config: %s", oidc_issuer)
|
|
48
|
+
|
|
49
|
+
req = urllib.request.Request(
|
|
50
|
+
f"{oidc_issuer}/.well-known/openid-configuration", headers={"Accept": "application/json"}
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
with urllib.request.urlopen(req, timeout=15) as response:
|
|
54
|
+
data = response.read()
|
|
55
|
+
issuer_config: Dict[str, Any] = json.loads(data)
|
|
56
|
+
|
|
57
|
+
if not issuer_config:
|
|
58
|
+
raise ValueError("Response doesn't contain issuer config.")
|
|
59
|
+
|
|
60
|
+
return issuer_config
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def assume_aws_role_with_web_identity(
|
|
64
|
+
oidc_access_token: str,
|
|
65
|
+
role_arn: str,
|
|
66
|
+
role_session_name: str,
|
|
67
|
+
region: str,
|
|
68
|
+
key_duration_seconds: int,
|
|
69
|
+
) -> Dict[str, Any]:
|
|
70
|
+
"""Request AWS STS credentials using the OIDC access token as a web identity."""
|
|
71
|
+
logger.debug(
|
|
72
|
+
"assume_aws_role_with_web_identity: %s, %s, %s, %s, %s",
|
|
73
|
+
mask_sensitive_data(oidc_access_token),
|
|
74
|
+
role_arn,
|
|
75
|
+
role_session_name,
|
|
76
|
+
region,
|
|
77
|
+
key_duration_seconds,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
sts_client = boto3.client("sts", region_name=region)
|
|
81
|
+
sts_response = sts_client.assume_role_with_web_identity(
|
|
82
|
+
RoleArn=role_arn,
|
|
83
|
+
RoleSessionName=role_session_name,
|
|
84
|
+
WebIdentityToken=oidc_access_token,
|
|
85
|
+
DurationSeconds=key_duration_seconds,
|
|
86
|
+
)
|
|
87
|
+
credentials: Dict[str, Any] = sts_response.get("Credentials", {})
|
|
88
|
+
if not all(k in credentials for k in ("AccessKeyId", "SecretAccessKey", "SessionToken")):
|
|
89
|
+
raise ValueError("Incomplete AWS credentials received.")
|
|
90
|
+
return credentials
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_aws_client(service_name: str, credentials: Dict[str, Any], region: str) -> boto3.client:
|
|
94
|
+
"""Create a boto3 client with the given credentials."""
|
|
95
|
+
logger.debug("get_issuer_config: %s, %s, %s", service_name, mask_sensitive_data(credentials), region)
|
|
96
|
+
|
|
97
|
+
return boto3.client(
|
|
98
|
+
service_name,
|
|
99
|
+
region_name=region,
|
|
100
|
+
aws_access_key_id=credentials.get("AccessKeyId"),
|
|
101
|
+
aws_secret_access_key=credentials.get("SecretAccessKey"),
|
|
102
|
+
aws_session_token=credentials.get("SessionToken"),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def get_ecr_auth_token(credentials: Dict[str, Any], registry_id: str, region: str) -> str:
|
|
107
|
+
"""Retrieve the AWS ECR authentication token using temporary AWS credentials."""
|
|
108
|
+
logger.debug("get_ecr_auth_token: %s, %s, %s", mask_sensitive_data(credentials), registry_id, region)
|
|
109
|
+
|
|
110
|
+
ecr_client = get_aws_client("ecr", credentials, region)
|
|
111
|
+
response = ecr_client.get_authorization_token(registryIds=[registry_id])
|
|
112
|
+
auth_data = response.get("authorizationData", [])
|
|
113
|
+
|
|
114
|
+
if not auth_data:
|
|
115
|
+
raise ValueError("Failed to retrieve ECR authorization data.")
|
|
116
|
+
|
|
117
|
+
auth_token: str = auth_data[0].get("authorizationToken", "")
|
|
118
|
+
if not auth_token:
|
|
119
|
+
raise ValueError("Failed to retrieve ECR authentication token.")
|
|
120
|
+
|
|
121
|
+
return auth_token
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def get_ca_auth_token(credentials: Dict[str, Any], domain: str, region: str) -> str:
|
|
125
|
+
"""Retrieve the AWS CodeArtifact authentication token using temporary AWS credentials."""
|
|
126
|
+
logger.debug("get_ca_auth_token: %s, %s, %s", mask_sensitive_data(credentials), domain, region)
|
|
127
|
+
|
|
128
|
+
ca_client = get_aws_client("codeartifact", credentials, region)
|
|
129
|
+
response = ca_client.get_authorization_token(domain=domain)
|
|
130
|
+
|
|
131
|
+
auth_token: str = response.get("authorizationToken", "")
|
|
132
|
+
if not auth_token:
|
|
133
|
+
raise ValueError("Failed to retrieve CodeArtifact authentication token.")
|
|
134
|
+
|
|
135
|
+
return auth_token
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def get_client_secret() -> str:
|
|
139
|
+
"""Get the client secret from environment or prompt user."""
|
|
140
|
+
client_secret = os.environ.get("CS_AWS_OIDC_CLIENT_SECRET", "")
|
|
141
|
+
if not client_secret:
|
|
142
|
+
client_secret = getpass.getpass("Please enter your OIDC client secret: ")
|
|
143
|
+
if not client_secret:
|
|
144
|
+
raise ValueError("Client secret is required.")
|
|
145
|
+
return client_secret
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def get_client_access_token(oidc_issuer: str, client_id: str, client_secret: str) -> str:
|
|
149
|
+
"""Get the OIDC access token using static client credentials."""
|
|
150
|
+
logger.debug(
|
|
151
|
+
"get_client_access_token: %s, %s, %s",
|
|
152
|
+
oidc_issuer,
|
|
153
|
+
mask_sensitive_data(client_id),
|
|
154
|
+
mask_sensitive_data(client_secret),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
token_endpoint: str = get_issuer_config(oidc_issuer).get("token_endpoint", "")
|
|
158
|
+
if not token_endpoint:
|
|
159
|
+
raise ValueError("Token endpoint not found in issuer config.")
|
|
160
|
+
|
|
161
|
+
payload = {
|
|
162
|
+
"grant_type": "client_credentials",
|
|
163
|
+
"client_id": client_id,
|
|
164
|
+
"client_secret": client_secret,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
data = urllib.parse.urlencode(payload).encode("ascii")
|
|
168
|
+
|
|
169
|
+
req = urllib.request.Request(
|
|
170
|
+
token_endpoint,
|
|
171
|
+
data=data,
|
|
172
|
+
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
with urllib.request.urlopen(req, timeout=15) as response:
|
|
176
|
+
response_data = response.read()
|
|
177
|
+
token_data = json.loads(response_data)
|
|
178
|
+
|
|
179
|
+
access_token: str = token_data.get("access_token", "")
|
|
180
|
+
if not access_token:
|
|
181
|
+
raise ValueError("Response doesn't contain access_token.")
|
|
182
|
+
|
|
183
|
+
return access_token
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def get_user_access_token(oidc_issuer: str, client_id: str, client_secret: str) -> str:
|
|
187
|
+
"""Get the OIDC access token via user authentication flow."""
|
|
188
|
+
logger.debug(
|
|
189
|
+
"get_user_access_token: %s, %s, %s",
|
|
190
|
+
oidc_issuer,
|
|
191
|
+
mask_sensitive_data(client_id),
|
|
192
|
+
mask_sensitive_data(client_secret),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
rp = RPServer(
|
|
196
|
+
oidc_issuer=oidc_issuer,
|
|
197
|
+
client_id=client_id,
|
|
198
|
+
client_secret=client_secret,
|
|
199
|
+
)
|
|
200
|
+
rp.start()
|
|
201
|
+
|
|
202
|
+
# Session info is mutable dict, modified in RPServer.
|
|
203
|
+
session_info: dict = {}
|
|
204
|
+
auth_url = rp.get_auth_url(session_info, use_pkce=True)
|
|
205
|
+
|
|
206
|
+
webbrowser.open(auth_url)
|
|
207
|
+
while not rp.srv.auth_code: # type: ignore
|
|
208
|
+
time.sleep(0.1)
|
|
209
|
+
|
|
210
|
+
request_args = {"code": rp.srv.auth_code, "code_verifier": rp.pkce_verifier} # type: ignore
|
|
211
|
+
|
|
212
|
+
resp = rp.client.do_access_token_request(
|
|
213
|
+
request_args=request_args,
|
|
214
|
+
state=session_info["state"],
|
|
215
|
+
authn_method="client_secret_basic",
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
access_token: str = resp["access_token"]
|
|
219
|
+
|
|
220
|
+
rp.shutdown()
|
|
221
|
+
return access_token
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def get_access_token(args: argparse.Namespace) -> str:
|
|
225
|
+
"""Get the appropriate OIDC access token based on args."""
|
|
226
|
+
logger.debug("get_access_token: %s", mask_sensitive_data(args))
|
|
227
|
+
|
|
228
|
+
client_secret = get_client_secret()
|
|
229
|
+
|
|
230
|
+
if args.static_oidc:
|
|
231
|
+
return get_client_access_token(args.oidc_issuer, args.client_id, client_secret)
|
|
232
|
+
else:
|
|
233
|
+
return get_user_access_token(args.oidc_issuer, args.client_id, client_secret)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def get_aws_credentials(args: argparse.Namespace, access_token: str) -> Dict[str, Any]:
|
|
237
|
+
"""Get AWS credentials using the OIDC access token."""
|
|
238
|
+
logger.debug("get_aws_credentials: %s, %s", mask_sensitive_data(args), mask_sensitive_data(access_token))
|
|
239
|
+
|
|
240
|
+
return assume_aws_role_with_web_identity(
|
|
241
|
+
access_token,
|
|
242
|
+
args.aws_role_arn,
|
|
243
|
+
args.aws_role_session_name,
|
|
244
|
+
args.aws_region,
|
|
245
|
+
args.aws_key_duration,
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def action_ecr_auth_token(args: argparse.Namespace) -> str:
|
|
250
|
+
"""Action to retrieve an ECR auth token."""
|
|
251
|
+
logger.debug("action_ecr_auth_token: %s", mask_sensitive_data(args))
|
|
252
|
+
|
|
253
|
+
access_token = get_access_token(args)
|
|
254
|
+
credentials = get_aws_credentials(args, access_token)
|
|
255
|
+
auth_token = get_ecr_auth_token(credentials, args.aws_tenant_id, args.aws_region)
|
|
256
|
+
|
|
257
|
+
if not args.quiet:
|
|
258
|
+
print("\033[1;32mAuthentication successful.\033[0m You can now proceed with docker commands:")
|
|
259
|
+
print()
|
|
260
|
+
print(
|
|
261
|
+
f"echo '{auth_token}' | base64 -d | cut -d: -f2 | docker login --username AWS --password-stdin "
|
|
262
|
+
f"{args.aws_tenant_id}.dkr.ecr.{args.aws_region}.amazonaws.com"
|
|
263
|
+
)
|
|
264
|
+
print(
|
|
265
|
+
f"docker pull {args.aws_tenant_id}.dkr.ecr.{args.aws_region}.amazonaws.com/cs-central1-elements_platform:16.0.1"
|
|
266
|
+
)
|
|
267
|
+
else:
|
|
268
|
+
# In quiet mode, just print the auth token (for scripting)
|
|
269
|
+
print(auth_token)
|
|
270
|
+
|
|
271
|
+
return auth_token
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def action_ca_auth_token(args: argparse.Namespace) -> str:
|
|
275
|
+
"""Action to retrieve a CodeArtifact auth token."""
|
|
276
|
+
logger.debug("action_ca_auth_token: %s", mask_sensitive_data(args))
|
|
277
|
+
|
|
278
|
+
access_token = get_access_token(args)
|
|
279
|
+
credentials = get_aws_credentials(args, access_token)
|
|
280
|
+
ca_auth_token = get_ca_auth_token(credentials, args.aws_domain, args.aws_region)
|
|
281
|
+
|
|
282
|
+
print(ca_auth_token)
|
|
283
|
+
|
|
284
|
+
return ca_auth_token
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def action_index_url(args: argparse.Namespace) -> str:
|
|
288
|
+
"""Action to generate and display a PyPI index URL."""
|
|
289
|
+
logger.debug("action_index_url: %s", mask_sensitive_data(args))
|
|
290
|
+
|
|
291
|
+
ca_auth_token = action_ca_auth_token(args)
|
|
292
|
+
domain_owner = args.aws_role_arn.split(":")[4]
|
|
293
|
+
index_url = (
|
|
294
|
+
f"https://aws:{ca_auth_token}@"
|
|
295
|
+
f"{args.aws_domain}-{domain_owner}"
|
|
296
|
+
f".d.codeartifact.{args.aws_region}.amazonaws.com/pypi/elements/simple/"
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
if not args.quiet:
|
|
300
|
+
print("\033[1;32mAuthentication successful.\033[0m You can now use the following index URL:")
|
|
301
|
+
print(index_url)
|
|
302
|
+
print("For example, run:")
|
|
303
|
+
print(f"pip install -i {index_url} cs.spin")
|
|
304
|
+
else:
|
|
305
|
+
# In quiet mode, just print the URL (for scripting)
|
|
306
|
+
print(index_url)
|
|
307
|
+
|
|
308
|
+
return index_url
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def parse_arguments() -> argparse.Namespace:
|
|
312
|
+
"""Parse command line arguments."""
|
|
313
|
+
parser = argparse.ArgumentParser(
|
|
314
|
+
prog="csaccess",
|
|
315
|
+
description="Provides access to CONTACT artifact storage.",
|
|
316
|
+
)
|
|
317
|
+
parser.add_argument(
|
|
318
|
+
"action",
|
|
319
|
+
choices=["index-url", "ca-auth-token", "ecr-auth-token"],
|
|
320
|
+
default="index-url",
|
|
321
|
+
nargs="?",
|
|
322
|
+
help="Action to perform.",
|
|
323
|
+
)
|
|
324
|
+
parser.add_argument(
|
|
325
|
+
"--static-oidc",
|
|
326
|
+
action="store_true",
|
|
327
|
+
default=False,
|
|
328
|
+
help="Use static OIDC credentials.",
|
|
329
|
+
)
|
|
330
|
+
parser.add_argument("--aws-domain", default=DEFAULT_CONFIG["AWS_DOMAIN"], help="AWS domain name.")
|
|
331
|
+
parser.add_argument(
|
|
332
|
+
"--aws-key-duration",
|
|
333
|
+
type=int,
|
|
334
|
+
default=DEFAULT_CONFIG["AWS_KEY_DURATION"],
|
|
335
|
+
help="AWS key duration in seconds.",
|
|
336
|
+
)
|
|
337
|
+
parser.add_argument(
|
|
338
|
+
"--aws-region",
|
|
339
|
+
default=DEFAULT_CONFIG["AWS_REGION"],
|
|
340
|
+
help="AWS region name.",
|
|
341
|
+
)
|
|
342
|
+
parser.add_argument(
|
|
343
|
+
"--aws-tenant-id",
|
|
344
|
+
default=DEFAULT_CONFIG["AWS_TENANT_ID"],
|
|
345
|
+
help="AWS tenant ID.",
|
|
346
|
+
)
|
|
347
|
+
parser.add_argument(
|
|
348
|
+
"--aws-role-arn",
|
|
349
|
+
default=DEFAULT_CONFIG["AWS_ROLE_ARN"],
|
|
350
|
+
help="AWS role ARN for CodeArtifact and ECR access.",
|
|
351
|
+
)
|
|
352
|
+
parser.add_argument(
|
|
353
|
+
"--aws-role-session-name",
|
|
354
|
+
default=DEFAULT_CONFIG["AWS_ROLE_SESSION_NAME"],
|
|
355
|
+
help="AWS STS role session name.",
|
|
356
|
+
)
|
|
357
|
+
parser.add_argument(
|
|
358
|
+
"--oidc-issuer",
|
|
359
|
+
default=DEFAULT_CONFIG["OIDC_ISSUER"],
|
|
360
|
+
help="OIDC issuer URL for authentication.",
|
|
361
|
+
)
|
|
362
|
+
parser.add_argument(
|
|
363
|
+
"--client-id",
|
|
364
|
+
default=DEFAULT_CONFIG["OIDC_CLIENT_ID"],
|
|
365
|
+
help="OIDC client ID for authentication.",
|
|
366
|
+
)
|
|
367
|
+
parser.add_argument("--quiet", "-q", action="store_true", help="Only output the result without additional text.")
|
|
368
|
+
parser.add_argument(
|
|
369
|
+
"--verbose",
|
|
370
|
+
"-v",
|
|
371
|
+
action="store_true",
|
|
372
|
+
help="Be verbose.",
|
|
373
|
+
)
|
|
374
|
+
args = parser.parse_args()
|
|
375
|
+
logging.basicConfig(
|
|
376
|
+
format="[%(levelname)-8s] [%(name)s] [%(module)s] %(message)s",
|
|
377
|
+
stream=sys.stderr,
|
|
378
|
+
level=(logging.DEBUG if args.verbose else logging.INFO),
|
|
379
|
+
)
|
|
380
|
+
return args
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def main() -> None:
|
|
384
|
+
"""Main entry point."""
|
|
385
|
+
interface = {
|
|
386
|
+
"index-url": action_index_url,
|
|
387
|
+
"ca-auth-token": action_ca_auth_token,
|
|
388
|
+
"ecr-auth-token": action_ecr_auth_token,
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
args = parse_arguments()
|
|
392
|
+
interface[args.action](args)
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
if __name__ == "__main__":
|
|
396
|
+
main()
|
csaccess/__main__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- mode: python; coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 CONTACT Software GmbH
|
|
4
|
+
# https://www.contact-software.com/
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
from csaccess import main
|
|
20
|
+
|
|
21
|
+
main()
|
csaccess/constants.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- mode: python; coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2025 CONTACT Software GmbH
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# https://www.contact-software.com/
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Default constants for CS Access module.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
from typing import Dict, Any
|
|
13
|
+
|
|
14
|
+
DEFAULT_CONFIG: Dict[str, Any] = {
|
|
15
|
+
# AWS Constants
|
|
16
|
+
"AWS_DOMAIN": "contact",
|
|
17
|
+
"AWS_KEY_DURATION": 3600,
|
|
18
|
+
"AWS_REGION": "eu-central-1",
|
|
19
|
+
"AWS_TENANT_ID": "373369985286",
|
|
20
|
+
"AWS_ROLE_ARN": "arn:aws:iam::373369985286:role/cs-central1-codeartifact-ecr-read-role",
|
|
21
|
+
"AWS_ROLE_SESSION_NAME": "CodeArtifactSession",
|
|
22
|
+
# OIDC Constants
|
|
23
|
+
"OIDC_ISSUER": "https://login.contact-cloud.com/realms/contact",
|
|
24
|
+
"OIDC_CLIENT_ID": "central1-auth-oidc-read",
|
|
25
|
+
# Environment Variable Names
|
|
26
|
+
"ENV_CLIENT_SECRET": "CS_AWS_OIDC_CLIENT_SECRET",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_client_secret() -> str:
|
|
31
|
+
"""Get the client secret from environment variable."""
|
|
32
|
+
client_secret = os.environ.get(DEFAULT_CONFIG["ENV_CLIENT_SECRET"], "")
|
|
33
|
+
if not client_secret:
|
|
34
|
+
raise ValueError(f"Environment variable {DEFAULT_CONFIG['ENV_CLIENT_SECRET']} is required.")
|
|
35
|
+
return client_secret
|
csaccess/rp.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# -*- mode: python; coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 CONTACT Software GmbH
|
|
4
|
+
# https://www.contact-software.com/
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
from http import server
|
|
19
|
+
import threading
|
|
20
|
+
import logging
|
|
21
|
+
|
|
22
|
+
from oic import rndstr
|
|
23
|
+
from oic.oic import Client
|
|
24
|
+
from oic.oic.message import AuthorizationResponse, RegistrationResponse
|
|
25
|
+
from oic.utils.authn.client import CLIENT_AUTHN_METHOD
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class RPRequestHandler(server.BaseHTTPRequestHandler):
|
|
31
|
+
def parse_auth_response(self) -> None:
|
|
32
|
+
response = self.path[len("/callback?") :] # noqa: E203
|
|
33
|
+
logger.debug("Response: %s", response)
|
|
34
|
+
|
|
35
|
+
aresp = self.server.client.parse_response( # type: ignore
|
|
36
|
+
AuthorizationResponse, info=response, sformat="urlencoded"
|
|
37
|
+
)
|
|
38
|
+
self.server.auth_code = aresp["code"] # type: ignore
|
|
39
|
+
self.server.auth_event.set() # type: ignore
|
|
40
|
+
|
|
41
|
+
def do_GET(self) -> None:
|
|
42
|
+
if self.path.startswith("/callback?"):
|
|
43
|
+
logger.debug("Got callback GET.")
|
|
44
|
+
self.parse_auth_response()
|
|
45
|
+
|
|
46
|
+
# The tab is not closed automatically, we rely on the text instructions.
|
|
47
|
+
content = b"""
|
|
48
|
+
<!DOCTYPE html>
|
|
49
|
+
<html>
|
|
50
|
+
<head>
|
|
51
|
+
<title>Authentication Complete</title>
|
|
52
|
+
</head>
|
|
53
|
+
<body>
|
|
54
|
+
<h3>Authentication Complete</h3>
|
|
55
|
+
<p>This window will close automatically. If it doesn't, you can close it manually.</p>
|
|
56
|
+
<script>
|
|
57
|
+
// Try multiple approaches to close the window.
|
|
58
|
+
window.addEventListener('load', function() {
|
|
59
|
+
// First attempt
|
|
60
|
+
window.close();
|
|
61
|
+
|
|
62
|
+
// Second attempt - countdown and close.
|
|
63
|
+
let counter = 3;
|
|
64
|
+
const countdown = document.createElement('p');
|
|
65
|
+
document.body.appendChild(countdown);
|
|
66
|
+
|
|
67
|
+
const timer = setInterval(function() {
|
|
68
|
+
countdown.textContent = 'Closing in ' + counter + ' seconds...';
|
|
69
|
+
counter--;
|
|
70
|
+
if (counter < 0) {
|
|
71
|
+
clearInterval(timer);
|
|
72
|
+
window.close();
|
|
73
|
+
}
|
|
74
|
+
}, 1000);
|
|
75
|
+
});
|
|
76
|
+
</script>
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
self.send_response(200, "Authentication Complete")
|
|
82
|
+
self.send_header("Content-type", "text/html")
|
|
83
|
+
self.send_header("Content-Length", str(len(content)))
|
|
84
|
+
self.end_headers()
|
|
85
|
+
self.wfile.write(content)
|
|
86
|
+
|
|
87
|
+
def do_POST(self) -> None:
|
|
88
|
+
if self.path.startswith("/callback"):
|
|
89
|
+
logger.debug("Got callback POST.")
|
|
90
|
+
self.send_response(200, "All good")
|
|
91
|
+
self.end_headers()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class RPServer(threading.Thread):
|
|
95
|
+
"""
|
|
96
|
+
Simple RP Service
|
|
97
|
+
|
|
98
|
+
Fires up an HTTP Server on 127.0.0.1 to receive the authorization code.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(self, *args, **kwargs) -> None: # type: ignore
|
|
102
|
+
self.port = 29398
|
|
103
|
+
|
|
104
|
+
self.issuer = kwargs.pop("oidc_issuer")
|
|
105
|
+
self.client_id = kwargs.pop("client_id")
|
|
106
|
+
client_info = {
|
|
107
|
+
"client_id": self.client_id,
|
|
108
|
+
"client_secret": kwargs.pop("client_secret"),
|
|
109
|
+
}
|
|
110
|
+
self.client_registration = RegistrationResponse(**client_info)
|
|
111
|
+
|
|
112
|
+
super().__init__(name="RP HTTPD", daemon=True)
|
|
113
|
+
|
|
114
|
+
self.client = Client(client_id=self.client_id, client_authn_method=CLIENT_AUTHN_METHOD)
|
|
115
|
+
provider_info = self.client.provider_config(self.issuer)
|
|
116
|
+
self.client.handle_provider_config(provider_info, self.issuer)
|
|
117
|
+
self.client.store_registration_info(self.client_registration)
|
|
118
|
+
|
|
119
|
+
self.pkce_verifier = None
|
|
120
|
+
self.addr = ("", self.port)
|
|
121
|
+
self.hdlr = RPRequestHandler
|
|
122
|
+
self.auth_event = threading.Event()
|
|
123
|
+
|
|
124
|
+
self.srv = server.HTTPServer(self.addr, self.hdlr)
|
|
125
|
+
self.srv.client = self.client # type: ignore
|
|
126
|
+
self.srv.timeout = 0.05 # Wakeup every 50ms
|
|
127
|
+
self.srv.auth_code = None # type: ignore
|
|
128
|
+
self.srv.auth_event = self.auth_event # type: ignore
|
|
129
|
+
self.srv.auth_event.clear() # type: ignore
|
|
130
|
+
|
|
131
|
+
self._shutdown_requested = False
|
|
132
|
+
|
|
133
|
+
def run(self) -> None:
|
|
134
|
+
try:
|
|
135
|
+
while not self._shutdown_requested:
|
|
136
|
+
self.srv.handle_request()
|
|
137
|
+
finally:
|
|
138
|
+
# Proper cleanup
|
|
139
|
+
if self.srv:
|
|
140
|
+
self.srv.server_close()
|
|
141
|
+
logger.debug("HTTP server closed.")
|
|
142
|
+
|
|
143
|
+
def shutdown(self) -> None:
|
|
144
|
+
"""Shut down the server and thread"""
|
|
145
|
+
logger.debug("Shutting down RPServer.")
|
|
146
|
+
self._shutdown_requested = True
|
|
147
|
+
|
|
148
|
+
# Wait for the thread to finish (with timeout).
|
|
149
|
+
if self.is_alive():
|
|
150
|
+
self.join(timeout=2.0)
|
|
151
|
+
|
|
152
|
+
# Force server shutdown if still alive.
|
|
153
|
+
if hasattr(self, "srv") and self.srv:
|
|
154
|
+
try:
|
|
155
|
+
self.srv.server_close()
|
|
156
|
+
logger.debug("Server resources released")
|
|
157
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
158
|
+
logger.error("Error during server cleanup: %s", e)
|
|
159
|
+
|
|
160
|
+
logger.debug("RPServer shutdown complete.")
|
|
161
|
+
|
|
162
|
+
def get_auth_url(
|
|
163
|
+
self,
|
|
164
|
+
session: dict | None = None,
|
|
165
|
+
extra_scopes: list | None = None,
|
|
166
|
+
login_hint: str | None = None,
|
|
167
|
+
use_pkce: bool = False,
|
|
168
|
+
) -> str:
|
|
169
|
+
if session is None:
|
|
170
|
+
session = {}
|
|
171
|
+
|
|
172
|
+
session["state"] = rndstr()
|
|
173
|
+
session["nonce"] = rndstr()
|
|
174
|
+
args = {
|
|
175
|
+
"client_id": self.client.client_id,
|
|
176
|
+
"response_type": "code",
|
|
177
|
+
"scope": ["openid"],
|
|
178
|
+
"nonce": session["nonce"],
|
|
179
|
+
"redirect_uri": [f"http://127.0.0.1:{self.port}/callback"],
|
|
180
|
+
"state": session["state"],
|
|
181
|
+
}
|
|
182
|
+
if use_pkce:
|
|
183
|
+
pkce_args, pkce_verifier = self.client.add_code_challenge()
|
|
184
|
+
args.update(pkce_args)
|
|
185
|
+
self.pkce_verifier = pkce_verifier
|
|
186
|
+
|
|
187
|
+
if extra_scopes:
|
|
188
|
+
args["scope"].extend(extra_scopes)
|
|
189
|
+
if login_hint:
|
|
190
|
+
args["login_hint"] = login_hint
|
|
191
|
+
|
|
192
|
+
auth_req = self.client.construct_AuthorizationRequest(request_args=args)
|
|
193
|
+
return str(auth_req.request(self.client.authorization_endpoint))
|
csaccess/utils.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# -*- mode: python; coding: utf-8 -*-
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 CONTACT Software GmbH
|
|
4
|
+
# https://www.contact-software.com/
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def mask_sensitive_data(data: Any, param_name: str = "", show_chars: int = 3) -> Any:
|
|
22
|
+
"""
|
|
23
|
+
Create a copy of the data with sensitive information masked.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
data: The data to be masked (dictionary, string, list, or None)
|
|
27
|
+
param_name: Optional name of the parameter (for context-aware masking)
|
|
28
|
+
show_chars: Number of characters to show before masking (0 for complete masking)
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Masked version of the input data
|
|
32
|
+
"""
|
|
33
|
+
if data is None:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
# Handle dictionary case (recursively).
|
|
37
|
+
if isinstance(data, dict):
|
|
38
|
+
result = {}
|
|
39
|
+
for key, value in data.items():
|
|
40
|
+
# Recursively mask nested values, passing the key name as context.
|
|
41
|
+
result[key] = mask_sensitive_data(value, key)
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
# Handle list case (recursively).
|
|
45
|
+
if isinstance(data, list):
|
|
46
|
+
return [mask_sensitive_data(item, param_name) for item in data]
|
|
47
|
+
|
|
48
|
+
# Handle string case.
|
|
49
|
+
if isinstance(data, str):
|
|
50
|
+
# Check if the parameter name or string content suggests sensitive data.
|
|
51
|
+
is_sensitive = param_name and any(
|
|
52
|
+
sensitive in param_name.lower() for sensitive in ["password", "token", "secret", "key", "auth"]
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# If the string itself contains obvious patterns, consider it sensitive.
|
|
56
|
+
if not is_sensitive and len(data) > 20:
|
|
57
|
+
# Check for patterns that suggest tokens or keys.
|
|
58
|
+
token_patterns = ["ey", "sk_", "ak_", "pk_", "key-", "sess-"]
|
|
59
|
+
is_sensitive = any(data.startswith(pattern) for pattern in token_patterns)
|
|
60
|
+
|
|
61
|
+
if is_sensitive:
|
|
62
|
+
if len(data) <= show_chars or show_chars <= 0:
|
|
63
|
+
return "***MASKED***"
|
|
64
|
+
else:
|
|
65
|
+
return data[:show_chars] + "***MASKED***"
|
|
66
|
+
|
|
67
|
+
return data
|
|
68
|
+
|
|
69
|
+
# For other types (int, bool, etc.), just return as is.
|
|
70
|
+
return data
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: csaccess
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python library for authenticating and accessing CONTACT resources in AWS.
|
|
5
|
+
Author-email: Alexander Vetski <alexander.vetski@contact-software.com>, Elias Haag <elias.haag@contact-software.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
Project-URL: Homepage, https://contact-software.com
|
|
184
|
+
Classifier: Environment :: Console
|
|
185
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
186
|
+
Classifier: Intended Audience :: Developers
|
|
187
|
+
Classifier: Operating System :: OS Independent
|
|
188
|
+
Classifier: Programming Language :: Python :: 3
|
|
189
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
190
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
191
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
192
|
+
Classifier: Topic :: Software Development
|
|
193
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
194
|
+
Requires-Python: >=3.11
|
|
195
|
+
Description-Content-Type: text/x-rst
|
|
196
|
+
License-File: LICENSE
|
|
197
|
+
Requires-Dist: boto3~=1.38
|
|
198
|
+
Requires-Dist: oic~=1.7
|
|
199
|
+
Dynamic: license-file
|
|
200
|
+
|
|
201
|
+
=========
|
|
202
|
+
csaccess
|
|
203
|
+
=========
|
|
204
|
+
|
|
205
|
+
A Python library for authenticating and accessing CONTACT resources in AWS CodeArtifact and Elastic Container Registry (ECR) using OIDC.
|
|
206
|
+
|
|
207
|
+
Overview
|
|
208
|
+
--------
|
|
209
|
+
|
|
210
|
+
``csaccess`` simplifies access to CONTACT cloud resources by providing a streamlined authentication flow with support for both interactive user-based and automated service-based authentication methods.
|
|
211
|
+
|
|
212
|
+
Authentication Methods
|
|
213
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
214
|
+
|
|
215
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
216
|
+
| Feature | User OIDC | Static OIDC (Client Credentials) |
|
|
217
|
+
+========================+===============================================+===================================================+
|
|
218
|
+
| **Authentication** | Interactive user login via web browser | Application authenticates itself using its secret |
|
|
219
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
220
|
+
| **Grant Type** | Authorization Code with PKCE | Client Credentials |
|
|
221
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
222
|
+
| **User Context** | Represents a specific user | Represents the application/service itself |
|
|
223
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
224
|
+
| **Security** | Relies on user credentials and browser | Relies on the client secret's security |
|
|
225
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
226
|
+
| **Use Cases** | Applications acting on behalf of a user | Service accounts, background processes |
|
|
227
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
228
|
+
| **Token Audience** | Targeted to specific user and application | Targeted to the application |
|
|
229
|
+
+------------------------+-----------------------------------------------+---------------------------------------------------+
|
|
230
|
+
|
|
231
|
+
**Security Warning:** Be extremely careful when handling access tokens. Treat them like passwords:
|
|
232
|
+
|
|
233
|
+
- Avoid logging them or storing them insecurely
|
|
234
|
+
- Never paste sensitive tokens into untrusted online services
|
|
235
|
+
- Use environment variables where possible to avoid exposing secrets
|
|
236
|
+
|
|
237
|
+
Installation
|
|
238
|
+
------------
|
|
239
|
+
|
|
240
|
+
.. code-block:: bash
|
|
241
|
+
|
|
242
|
+
pip install csaccess
|
|
243
|
+
|
|
244
|
+
Setup and Configuration
|
|
245
|
+
-----------------------
|
|
246
|
+
|
|
247
|
+
Configuration
|
|
248
|
+
~~~~~~~~~~~~~
|
|
249
|
+
|
|
250
|
+
- The "relying party" local server requires port **29398** to be free and available
|
|
251
|
+
- Set environment variables to avoid interactive prompts:
|
|
252
|
+
|
|
253
|
+
On Linux / macOS:
|
|
254
|
+
|
|
255
|
+
.. code-block:: bash
|
|
256
|
+
|
|
257
|
+
export CS_AWS_OIDC_CLIENT_SECRET="<OIDC-client-secret>"
|
|
258
|
+
|
|
259
|
+
Windows CMD:
|
|
260
|
+
|
|
261
|
+
.. code-block:: bash
|
|
262
|
+
|
|
263
|
+
set CS_AWS_OIDC_CLIENT_SECRET="<OIDC-client-secret>"
|
|
264
|
+
|
|
265
|
+
Windows PowerShell:
|
|
266
|
+
|
|
267
|
+
.. code-block:: bash
|
|
268
|
+
|
|
269
|
+
$env:CS_AWS_OIDC_CLIENT_SECRET = "<OIDC-client-secret>"
|
|
270
|
+
|
|
271
|
+
Usage Examples
|
|
272
|
+
--------------
|
|
273
|
+
|
|
274
|
+
**Important:**: unset AWS specific vars existing in local env as they will interfere with AWS STS functionality.
|
|
275
|
+
|
|
276
|
+
.. code-block:: bash
|
|
277
|
+
|
|
278
|
+
unset AWS_PROFILE
|
|
279
|
+
unset AWS_DEFAULT_PROFILE
|
|
280
|
+
unset AWSUME_PROFILE
|
|
281
|
+
unset AWSUME_COMMAND
|
|
282
|
+
|
|
283
|
+
Basic Usage
|
|
284
|
+
~~~~~~~~~~~
|
|
285
|
+
|
|
286
|
+
Get PyPI index URL with embedded auth token (default action):
|
|
287
|
+
|
|
288
|
+
.. code-block:: python
|
|
289
|
+
|
|
290
|
+
import csaccess
|
|
291
|
+
index_url = csaccess.get_index_url()
|
|
292
|
+
|
|
293
|
+
Command-Line Interface
|
|
294
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
295
|
+
|
|
296
|
+
Returns the CodeArtifact URL with an injected token (default):
|
|
297
|
+
|
|
298
|
+
.. code-block:: bash
|
|
299
|
+
|
|
300
|
+
python -m csaccess
|
|
301
|
+
|
|
302
|
+
Get the CodeArtifact token:
|
|
303
|
+
|
|
304
|
+
.. code-block:: bash
|
|
305
|
+
|
|
306
|
+
python -m csaccess ca-auth-token
|
|
307
|
+
|
|
308
|
+
Get the ECR token:
|
|
309
|
+
|
|
310
|
+
.. code-block:: bash
|
|
311
|
+
|
|
312
|
+
python -m csaccess ecr-auth-token
|
|
313
|
+
|
|
314
|
+
Integration Examples
|
|
315
|
+
--------------------
|
|
316
|
+
|
|
317
|
+
Following are examples for Linux / macOS:
|
|
318
|
+
|
|
319
|
+
Using with pip
|
|
320
|
+
~~~~~~~~~~~~~~
|
|
321
|
+
|
|
322
|
+
.. code-block:: bash
|
|
323
|
+
|
|
324
|
+
INDEX_URL=$(python -m csaccess --quiet)
|
|
325
|
+
pip install -i $INDEX_URL your-private-package
|
|
326
|
+
|
|
327
|
+
Using with Docker
|
|
328
|
+
~~~~~~~~~~~~~~~~~
|
|
329
|
+
|
|
330
|
+
.. code-block:: bash
|
|
331
|
+
|
|
332
|
+
ECR_TOKEN=$(python -m csaccess ecr-auth-token --quiet)
|
|
333
|
+
echo $ECR_TOKEN | docker login -u AWS --password-stdin <ECR-registry-url>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
csaccess/__init__.py,sha256=68NDBFf_dQ0IjteAy7ABA-eMD3zjD05VI3eViUzF1c8,13138
|
|
2
|
+
csaccess/__main__.py,sha256=hR3GY7dhLmSHoe1hR_UVuBT3OYGnHaIenDqNALjrzEw,697
|
|
3
|
+
csaccess/constants.py,sha256=jrTLD9-ozidhTuTC8KItvOZVEHpOBJx0GdFlY9iXHlE,1111
|
|
4
|
+
csaccess/rp.py,sha256=wWkCkU1yXEJk-dymc3RCSQuPs63jCg9QZPCGFJpKLb0,6805
|
|
5
|
+
csaccess/utils.py,sha256=1UvDuFQRrMEN1cXHxhD2L8BfHVPn9vILYDCp_P4UkO0,2587
|
|
6
|
+
csaccess-0.0.1.dist-info/licenses/LICENSE,sha256=4MAecetnRTQw5DlHtiikDSzKWO1xVLwzM5_DsPMYlnE,10172
|
|
7
|
+
csaccess-0.0.1.dist-info/METADATA,sha256=5-mCswvigW1W9biP_aGBPi-0CzjLHF8SSsv-orRTTwA,16962
|
|
8
|
+
csaccess-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
csaccess-0.0.1.dist-info/entry_points.txt,sha256=3zj3FW5LuPZrMpNmx_qFFI-5Jvg4iBk2fCes_3Cr5Cs,43
|
|
10
|
+
csaccess-0.0.1.dist-info/top_level.txt,sha256=VOPNz0PQhPfzdEc-oJc5CcCTrO0XZ5wOynYKTkl4z8I,9
|
|
11
|
+
csaccess-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
csaccess
|