Skip to content

Commit f8e2b43

Browse files
feat(ContainerAuthenticator): add support for code engine workload (#296)
Signed-off-by: Sascha Schwarze <[email protected]>
1 parent b1326c5 commit f8e2b43

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Authentication.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ const service = ExampleServiceV1.newInstance(options);
356356
## Container Authentication
357357
The `ContainerAuthenticator` is intended to be used by application code
358358
running inside a compute resource managed by the IBM Kubernetes Service (IKS)
359-
in which a secure compute resource token (CR token) has been stored in a file
360-
within the compute resource's local file system.
359+
or IBM Cloud Code Engine in which a secure compute resource token (CR token)
360+
has been stored in a file within the compute resource's local file system.
361361
The CR token is similar to an IAM apikey except that it is managed automatically by
362-
the compute resource provider (IKS).
362+
the compute resource provider (IKS or Code Engine).
363363
This allows the application developer to:
364364
- avoid storing credentials in application code, configuration files or a password vault
365365
- avoid managing or rotating credentials
@@ -379,7 +379,9 @@ The IAM access token is added to each outbound request in the `Authorization` he
379379

380380
- crTokenFilename: (optional) the name of the file containing the injected CR token value.
381381
If not specified, then the authenticator will first try `/var/run/secrets/tokens/vault-token`
382-
and then `/var/run/secrets/tokens/sa-token` as the default value (first file found is used).
382+
and then `/var/run/secrets/tokens/sa-token` and finally
383+
`/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token` as the default value
384+
(first file found is used).
383385
The application must have `read` permissions on the file containing the CR token value.
384386

385387
- iamProfileName: (optional) the name of the linked trusted IAM profile to be used when obtaining the

auth/token-managers/container-token-manager.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2021, 2024.
2+
* (C) Copyright IBM Corp. 2021, 2025.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import { IamRequestBasedTokenManager, IamRequestOptions } from './iam-request-ba
2121

2222
const DEFAULT_CR_TOKEN_FILEPATH1 = '/var/run/secrets/tokens/vault-token';
2323
const DEFAULT_CR_TOKEN_FILEPATH2 = '/var/run/secrets/tokens/sa-token';
24+
const DEFAULT_CR_TOKEN_FILEPATH3 =
25+
'/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token';
2426

2527
/** Configuration options for IAM token retrieval. */
2628
interface Options extends IamRequestOptions {
@@ -144,6 +146,7 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
144146
* 1. User-specified filename (if specified)
145147
* 2. Default file #1 (/var/run/secrets/tokens/vault-token)
146148
* 3. Default file #2 (/var/run/secrets/tokens/sa-token)
149+
* 4. Default file #3 (/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token)
147150
* First one found wins.
148151
*
149152
* @returns the CR token value as a string
@@ -159,7 +162,11 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
159162
try {
160163
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH1);
161164
} catch (err) {
162-
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
165+
try {
166+
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
167+
} catch (err1) {
168+
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH3);
169+
}
163170
}
164171
}
165172
return crToken;

0 commit comments

Comments
 (0)