Skip to content

chore(token-providers): add feature ID 'BEARER_SERVICE_ENV_VARS' #7168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/submodules/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./emitWarningIfUnsupportedVersion";
export * from "./setCredentialFeature";
export * from "./setFeature";
export * from "./setTokenFeature";
17 changes: 17 additions & 0 deletions packages/core/src/submodules/client/setTokenFeature.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AttributedTokenIdentity } from "@aws-sdk/types";
import { describe, expect, test as it } from "vitest";

import { setTokenFeature } from "./setTokenFeature";

describe(setTokenFeature.name, () => {
it("should create the data path if it does't exist", () => {
const token = { token: "" } as AttributedTokenIdentity;

expect(setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3")).toEqual({
token: "",
$source: {
BEARER_SERVICE_ENV_VARS: "3",
},
});
});
});
18 changes: 18 additions & 0 deletions packages/core/src/submodules/client/setTokenFeature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { AttributedTokenIdentity, AwsSdkTokenFeatures } from "@aws-sdk/types";

/**
* @internal
*
* @returns the token with source feature attribution.
*/
export function setTokenFeature<F extends keyof AwsSdkTokenFeatures>(
token: AttributedTokenIdentity,
feature: F,
value: AwsSdkTokenFeatures[F]
): AttributedTokenIdentity {
if (!token.$source) {
token.$source = {};
}
token.$source![feature] = value;
return token;
}
11 changes: 8 additions & 3 deletions packages/token-providers/src/fromEnvSigningName.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getBearerTokenEnvKey } from "@aws-sdk/core";
import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

import { fromEnvSigningName } from "./fromEnvSigningName";

vi.mock("@aws-sdk/core");
vi.mock("@aws-sdk/core/httpAuthSchemes");

describe(fromEnvSigningName.name, () => {
const originalEnv = process.env;
Expand Down Expand Up @@ -40,7 +40,12 @@ describe(fromEnvSigningName.name, () => {
const mockBearerToken = "mock-bearer-token";
process.env[mockBearerTokenEnvKey] = mockBearerToken;
const token = await fromEnvSigningName(mockInit)();
expect(token).toEqual({ token: mockBearerToken });
expect(token).toEqual({
token: mockBearerToken,
$source: {
BEARER_SERVICE_ENV_VARS: "3",
},
});
expect(getBearerTokenEnvKey).toHaveBeenCalledWith(mockInit.signingName);
});
});
10 changes: 7 additions & 3 deletions packages/token-providers/src/fromEnvSigningName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getBearerTokenEnvKey } from "@aws-sdk/core";
import type { CredentialProviderOptions, TokenIdentityProvider } from "@aws-sdk/types";
import { setTokenFeature } from "@aws-sdk/core/client";
import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
import type { AttributedTokenIdentity, CredentialProviderOptions, TokenIdentityProvider } from "@aws-sdk/types";
import { TokenProviderError } from "@smithy/property-provider";

/**
Expand Down Expand Up @@ -33,5 +34,8 @@ export const fromEnvSigningName =
throw new TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
}

return { token: process.env[bearerTokenKey]! };
const token = { token: process.env[bearerTokenKey]! } as AttributedTokenIdentity;
setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");

return token;
};
10 changes: 9 additions & 1 deletion packages/types/src/feature-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export type AwsSdkFeatures = Partial<{
FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED: "c";
DDB_MAPPER: "d";
}> &
AwsSdkCredentialsFeatures;
AwsSdkCredentialsFeatures &
AwsSdkTokenFeatures;

/**
* @internal
Expand Down Expand Up @@ -62,3 +63,10 @@ export type AwsSdkCredentialsFeatures = Partial<{
CREDENTIALS_HTTP: "z";
CREDENTIALS_IMDS: "0";
}>;

/**
* @internal
*/
export type AwsSdkTokenFeatures = Partial<{
BEARER_SERVICE_ENV_VARS: "3";
}>;
12 changes: 12 additions & 0 deletions packages/types/src/identity/TokenIdentity.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import type { TokenIdentity } from "@smithy/types";

import type { AwsSdkTokenFeatures } from "../feature-ids";
export { TokenIdentity, TokenIdentityProvider } from "@smithy/types";

/**
* @public
*
* TokenIdentity with source attribution metadata.
*/
export type AttributedTokenIdentity = TokenIdentity & {
$source?: AwsSdkTokenFeatures;
};
Loading