Skip to content
Closed
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
27 changes: 22 additions & 5 deletions cdk/src/stacks/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ export interface AgentStackProps extends StackProps {
readonly features?: DeploymentFeatures;
}

/**
* Whether the Linear OAuth token vault is deployed. An explicit context value wins;
* otherwise `byDefault` (on when Linear and AgentCore are both deployed: see the call site).
*/
function resolveLinearIdentityVault(context: unknown, byDefault: boolean): boolean {
if (context === true || context === 'true') return true;
if (context === false || context === 'false') return false;
if (context !== undefined) throw new Error('enableLinearIdentityVault must be true or false');
return byDefault;
}

export class AgentStack extends Stack {
/** The REST API and its Cognito user pool; the operator console stack signs users in against these. */
public readonly taskApi: TaskApi;
Expand Down Expand Up @@ -325,11 +336,17 @@ export class AgentStack extends Stack {
// unchanged and introduces no new CFN types into the bootstrap policy set.
const toolGatewayEnabled = features.toolGateway;

// RFC #249 Phase 1 (Linear OAuth token vault). Additive + default-off:
// resolved here (early) so the agent runtime env map + the LinearIdentityVault
// construct + the token grants all key off one predicate and cannot drift.
const linearIdentityVaultEnabled = this.node.tryGetContext('enableLinearIdentityVault') === true
|| this.node.tryGetContext('enableLinearIdentityVault') === 'true';
// RFC #249 Linear OAuth token vault (AgentCore Identity). Default ON wherever
// Linear and AgentCore are both deployed: AgentCore already proves the region
// has it, and the vault refreshes the Linear grant itself, so an idle workspace
// cannot strand an expired refresh token in Secrets Manager. Deployments without
// AgentCore default to Secrets Manager, and without Linear there is no grant to
// vault. `--context enableLinearIdentityVault=true|false` overrides the default
// (an explicit true without Linear still fails below). Resolved early so the
// runtime env map, the LinearIdentityVault construct and the token grants share
// one predicate.
const linearIdentityVaultEnabled = resolveLinearIdentityVault(
this.node.tryGetContext('enableLinearIdentityVault'), agentCoreEnabled && features.linear);
if (linearIdentityVaultEnabled && !features.linear) {
throw new Error('enableLinearIdentityVault requires the linear feature; enable Linear or drop the vault switch');
}
Expand Down
29 changes: 25 additions & 4 deletions cdk/test/stacks/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,10 @@ describe('AgentStack solution attribution (#319): AWS_SDK_UA_APP_ID via stack-le
// A loose `toBeGreaterThan` let a whole integration construct disappear
// unnoticed; the exact count fails if a Lambda is dropped OR if a new one
// is added without being attributed below.
// 47 = 46 on main + RemoveWorkspaceFn (DELETE /v1/linear/workspaces/{slug}).
expect(abcaLambdas.length).toBe(47);
// 47 = 46 on main + RemoveWorkspaceFn (DELETE /v1/linear/workspaces/{slug});
// 49 now that the Linear identity vault is on by default (its provider
// onEvent handler and the provider framework function).
expect(abcaLambdas.length).toBe(49);
// Every ABCA-authored Lambda must carry the canonical `#` app-id. Collect
// any offenders so a failure names the exact logical id(s) that are naked.
const unattributed = abcaLambdas
Expand Down Expand Up @@ -1768,8 +1770,21 @@ describe('AgentStack tool-gateway gate (ADR-019 P1)', () => {
});

describe('AgentStack Linear identity vault gate (#809)', () => {
test('default synth omits the vault: no workload identity, no token grant, no agent env', () => {
const app = new App();
test('default synth (AgentCore) provisions the vault and its hosted consent page', () => {
const rendered = JSON.stringify(Template.fromStack(new AgentStack(new App(), 'LinearVaultDefaultStack', {
env: { account: '123456789012', region: 'us-east-1' },
})).toJSON());
expect(rendered).toContain('Custom::LinearWorkloadIdentity');
expect(rendered).toContain('GetResourceOauth2Token');
expect(rendered).toContain('LINEAR_WORKLOAD_IDENTITY_NAME');
expect(rendered).toContain('LinearVaultConsentUrl');
});

test.each([
['explicit opt-out', { enableLinearIdentityVault: 'false' }],
['a deployment without AgentCore', { compute_types: 'ecs' }],
])('%s omits the vault: no workload identity, no token grant, no agent env', (_label, context) => {
const app = new App({ context });
const stack = new AgentStack(app, 'LinearVaultOffStack', {
env: { account: '123456789012', region: 'us-east-1' },
});
Expand All @@ -1782,6 +1797,12 @@ describe('AgentStack Linear identity vault gate (#809)', () => {
expect(rendered).not.toContain('LinearVaultConsentUrl');
});

test('an unrecognised flag value fails synth instead of silently choosing a store', () => {
expect(() => new AgentStack(new App({ context: { enableLinearIdentityVault: 'yes' } }), 'LinearVaultBadStack', {
env: { account: '123456789012', region: 'us-east-1' },
})).toThrow('enableLinearIdentityVault must be true or false');
});

test('flag on: agent runtime role gets the token data-plane grant + the agent env is set', () => {
const app = new App({ context: { enableLinearIdentityVault: true } });
const template = Template.fromStack(
Expand Down
6 changes: 5 additions & 1 deletion cdk/test/stacks/compute-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ describe.each([
{ label: 'legacy ECS', selector: { compute_type: 'ecs' }, backends: ['agentcore', 'ecs'] },
{ label: 'ECS default with AgentCore', selector: { compute_types: ['ecs', 'agentcore'] }, backends: ['ecs', 'agentcore'] },
{ label: 'MicroVM default without AgentCore', selector: { compute_types: 'lambda-microvm,ecs' }, backends: ['lambda-microvm', 'ecs'] },
{ label: 'all backends', selector: { compute_types: 'agentcore,ecs,lambda-microvm' }, backends: ['agentcore', 'ecs', 'lambda-microvm'] },
// All three backends with the inline network is an expected census rejection
// (`additive-agentcore+ecs+lambda-microvm-default-inline`, over the 490 budget);
// pin the default-on vault off so this backend-wiring test stays under
// CloudFormation's 500-resource limit. The vault itself is covered in agent.test.
{ label: 'all backends', selector: { compute_types: 'agentcore,ecs,lambda-microvm', enableLinearIdentityVault: 'false' }, backends: ['agentcore', 'ecs', 'lambda-microvm'] },
])('additive deployment from $label', ({ selector, backends }) => {
let template: Template;
beforeAll(() => {
Expand Down
16 changes: 9 additions & 7 deletions cli/src/commands/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ export function renderLinearAppTemplate(opts: LinearAppTemplateOptions = {}): st
]
: [
` ${callbackUrl}`,
' (loopback — needs the browser on this machine; deploy with',
' `--context enableLinearIdentityVault=true` for a hosted consent page)',
' (loopback — needs the browser on this machine; the Identity vault provides a',
' hosted consent page: on by default with AgentCore, or',
' `--context enableLinearIdentityVault=true`)',
]),
'',
' Public: OFF',
Expand Down Expand Up @@ -1228,7 +1229,8 @@ export function makeLinearCommand(): Command {
? ' `--code` resumes the Secrets Manager authorization-code flow. A vault workspace '
+ 'finishes its consent in one run — re-run without `--code`.'
: ` The stack '${stackName}' publishes no LinearVaultConsentUrl, so its last deploy `
+ 'omitted `--context enableLinearIdentityVault=true`. Re-deploy with it, or move '
+ 'had no Identity vault (no AgentCore, or `--context enableLinearIdentityVault=false`). '
+ 'Re-deploy with `--context enableLinearIdentityVault=true`, or move '
+ 'this workspace off the vault deliberately by deleting its registry row first.'),
);
}
Expand All @@ -1237,8 +1239,8 @@ export function makeLinearCommand(): Command {
// availability, only this stack's outputs. Naming the real cause is what lets
// an operator fix it, and the wrong cause sends them to the AWS region table.
console.log(
` Stack '${stackName}' has no Identity vault (deployed without `
+ '`--context enableLinearIdentityVault=true`) — using Secrets Manager.',
` Stack '${stackName}' has no Identity vault (deployed without AgentCore, or with `
+ '`--context enableLinearIdentityVault=false`) — using Secrets Manager.',
);
}

Expand Down Expand Up @@ -1462,8 +1464,8 @@ export function makeLinearCommand(): Command {
console.log(` Redirecting to: ${setupRedirectUri}`);
console.log(' That exact URI must be one of the app\'s Redirect URIs, or consent');
console.log(' fails with "Invalid redirect_uri parameter for the application".');
console.log(' No localhost on this machine? Deploy the consent page with');
console.log(' `--context enableLinearIdentityVault=true`.\n');
console.log(' No localhost on this machine? Re-deploy with');
console.log(' `--context enableLinearIdentityVault=true` for the hosted consent page.\n');
}
if (resumed || vaultAccessToken) {
// nothing to open: consent already happened in the operator's browser.
Expand Down
7 changes: 5 additions & 2 deletions docs/decisions/ADR-016-pluggable-identity-and-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

> **2026-08-28 implementation note — Phase 1 (Linear `ChannelCredential`) is built and live-verified
> on a dev stack** ([#809](https://github.com/aws-samples/sample-autonomous-cloud-coding-agents/issues/809)).
> Additive and context-gated (`enableLinearIdentityVault`, default off), with Secrets Manager retained
> as the fallback, so a deployment that does not opt in is byte-for-byte unchanged. The decision below
> Additive and context-gated (`enableLinearIdentityVault`), with Secrets Manager retained
> as the fallback. **Update:** the gate now defaults ON wherever AgentCore is deployed (which proves
> the region has AgentCore) and OFF otherwise; `enableLinearIdentityVault=true|false` overrides.
> Motivation: a Secrets Manager workspace left unused let its refresh token expire, failing every
> Linear trigger silently until a browser re-consent through the CLI's localhost callback. The decision below
> stands; two implementation details deviate from the P1 text and are recorded in *Phasing* → P1.

## Context
Expand Down
8 changes: 6 additions & 2 deletions docs/guides/LINEAR_SETUP_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ One of two places, chosen automatically at setup time:

| | When it's used | What's stored |
|---|---|---|
| **AgentCore Identity vault** | The stack was deployed with `--context enableLinearIdentityVault=true` | Nothing long-lived. AgentCore holds the refresh token and mints short-lived access tokens on demand. |
| **Secrets Manager** | Otherwise — including regions where AgentCore Identity isn't available | An OAuth token bundle in `bgagent-linear-oauth-<slug>`, refreshed and rotated by ABCA. |
| **AgentCore Identity vault** | **Default** whenever the stack deploys AgentCore (the standard deployment). A deployment without AgentCore (for example `compute_types=ecs`) can opt in with `--context enableLinearIdentityVault=true`, provided its region has AgentCore Identity | Nothing long-lived. AgentCore holds the refresh token and mints short-lived access tokens on demand. |
| **Secrets Manager** | Deployments without AgentCore, or `--context enableLinearIdentityVault=false` | An OAuth token bundle in `bgagent-linear-oauth-<slug>`, refreshed and rotated by ABCA only when ABCA uses Linear. |

Prefer the vault. With Secrets Manager, a workspace that ABCA does not use for long enough can be left with an expired refresh token, and re-authorizing needs a browser that can reach the CLI's `localhost` callback. The vault's hosted consent page works from any machine.

Existing vault deployments keep their resources and logical IDs, so turning the default on changes nothing for them. A Secrets Manager workspace on a stack that now has the vault keeps working until you re-run `bgagent linear setup <slug>`, which moves it to the vault.

The vault can be configured with any selected backend. Lambda MicroVMs remains experimental; its image must include the current shared configuration contract.

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions docs/src/content/docs/using/Linear-setup-guide.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading