Skip to content

Commit 9d25e01

Browse files
feat(ContainerAuthenticator): enhance ContainerAuthenticator to support Code Engine workload
1 parent fce3362 commit 9d25e01

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-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

+8-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,7 @@ 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 = '/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token';
2425

2526
/** Configuration options for IAM token retrieval. */
2627
interface Options extends IamRequestOptions {
@@ -144,6 +145,7 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
144145
* 1. User-specified filename (if specified)
145146
* 2. Default file #1 (/var/run/secrets/tokens/vault-token)
146147
* 3. Default file #2 (/var/run/secrets/tokens/sa-token)
148+
* 4. Default file #3 (/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token)
147149
* First one found wins.
148150
*
149151
* @returns the CR token value as a string
@@ -159,7 +161,11 @@ export class ContainerTokenManager extends IamRequestBasedTokenManager {
159161
try {
160162
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH1);
161163
} catch (err) {
162-
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
164+
try {
165+
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH2);
166+
} catch (err) {
167+
crToken = readCrTokenFile(DEFAULT_CR_TOKEN_FILEPATH3);
168+
}
163169
}
164170
}
165171
return crToken;

0 commit comments

Comments
 (0)