Skip to content

fix: add try-catch block to authentication manager#336

Merged
swetabar merged 5 commits intomainfrom
add-try-catch-to-auth-manager
Aug 19, 2024
Merged

fix: add try-catch block to authentication manager#336
swetabar merged 5 commits intomainfrom
add-try-catch-to-auth-manager

Conversation

@swetabar
Copy link
Copy Markdown
Contributor

Related Issues

Add try-catch block to authentication-manager to try and figure out the issue with ScopedApiKeyHandler

@swetabar swetabar requested a review from blefebvre August 19, 2024 14:50
Copy link
Copy Markdown
Contributor

@blefebvre blefebvre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor item with the log statement.

Is an additional test case needed to hit the catch block?

Comment thread packages/spacecat-shared-http-utils/src/auth/authentication-manager.js Outdated
this.log(`No API key entity found in the data layer for the provided API key: ${apiKeyFromHeader}`, 'error');
return null;
}
this.log(`API Key entity: ${apiKeyEntity}`, 'debug');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this object be stringified?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these logs as we might not need them anymore.

@github-actions
Copy link
Copy Markdown

This PR will trigger a patch release when merged.

@swetabar
Copy link
Copy Markdown
Contributor Author

Minor item with the log statement.

Is an additional test case needed to hit the catch block?

Yes. Added the additional test case to fix the test errors.

@swetabar swetabar merged commit a6cf629 into main Aug 19, 2024
@swetabar swetabar deleted the add-try-catch-to-auth-manager branch August 19, 2024 16:40
adobe-bot pushed a commit that referenced this pull request Aug 19, 2024
# [@adobe/spacecat-shared-http-utils-v1.6.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-http-utils-v1.6.6...@adobe/spacecat-shared-http-utils-v1.6.7) (2024-08-19)

### Bug Fixes

* add try-catch block to authentication manager ([#336](#336)) ([a6cf629](a6cf629))
@adobe-bot
Copy link
Copy Markdown

🎉 This issue has been resolved in version @adobe/spacecat-shared-http-utils-v1.6.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

solaris007 added a commit that referenced this pull request Feb 19, 2026
…#1364)

## Why

SpaceCat Lambda functions currently use `@adobe/helix-shared-secrets` to
load secrets from AWS Secrets Manager. This couples secret management to
AWS administrative access - CAMP's 3 immutable roles (admin, power user,
read only) don't allow creating a restricted Secrets Manager-only role,
so anyone with AWS admin access can read all secrets. Following the S3
credentials leak incident (MSI0001036), moving secrets to HashiCorp
Vault was identified as remediation track #6: Vault provides a separate
auth boundary with granular ACLs, audit trail, and short-lived
credentials, fully de-coupled from AWS access.

This package enables the migration - services switch from `helixSecrets`
to `vaultSecrets` in their middleware chain with no other code changes.

## What

Adds `@adobe/spacecat-shared-vault-secrets` - a drop-in replacement for
`@adobe/helix-shared-secrets` that loads secrets from Vault instead of
AWS Secrets Manager. Same `.with()` middleware interface, same caching
strategy, different backend.

1. On cold start, reads bootstrap config from AWS Secrets Manager at
`/mysticat/bootstrap/{service-name}` (auto-resolved from
`ctx.func.name`) to get per-service Vault AppRole credentials
2. Authenticates to Vault via AppRole (role_id + secret_id)
3. Reads secrets from `dx_mysticat/{environment}/{service-name}` (KV V2)
4. Merges into `context.env` and `process.env`
5. Two-tier caching: 60s metadata check, 1h hard expiration

**Per-service credential isolation:** Each service gets its own AppRole,
its own policy, and its own bootstrap secret. A compromised service
credential can only read that service's secrets.

**HTTP call budget:** Cold start = 3 calls (AWS SM + AppRole login +
secret read). Warm invocation within 60s = 0 calls. Past 60s = 1 call
(metadata). Secret rotation = 2 calls (metadata + read).

### Files

| File | Purpose |
|------|---------
| `src/vault-client.js` | Vault HTTP client with private class fields
(AppRole login, KV V2 read, metadata, token renewal) |
| `src/bootstrap.js` | AWS Secrets Manager bootstrap loader
(aws4-signed, no SDK dependency) |
| `src/vault-secrets-wrapper.js` | Middleware wrapper (two-tier caching,
path resolution, concurrency lock, env merge) |
| `src/index.js` / `src/index.d.ts` | Exports and TypeScript
declarations |

### Usage

```js
import wrap from '@adobe/helix-shared-wrap';
import vaultSecrets from '@adobe/spacecat-shared-vault-secrets';

// Zero-config: bootstrapPath and Vault path both auto-resolve from ctx.func.name
export const main = wrap(run)
  .with(vaultSecrets)
  .with(helixStatus);
```

### Prerequisites

Each service in each AWS account (dev/stage/prod) needs:

1. **Per-service AppRole** in Vault - provisioned via
`cst-vault/vault_policies` PRs (done)

2. **Per-service bootstrap secret** in AWS Secrets Manager at
`/mysticat/bootstrap/{service-name}`:

```json
{
  "role_id": "<service-specific-approle-role-id>",
  "secret_id": "<service-specific-secret-id>",
  "vault_addr": "https://vault-amer.adobe.net",
  "mount_point": "dx_mysticat",
  "environment": "dev"
}
```

3. **VPC configuration** - Lambda must run in the SpaceCat VPC (private
subnets with NAT gateway). Vault rejects AppRole login from non-Adobe
IPs with HTTP 403.

4. **IAM permissions** - Lambda role needs
`secretsmanager:GetSecretValue` on `/mysticat/bootstrap/*`. Three IAM
policies updated in spacecat-infrastructure PR #336.

See the [package
README](packages/spacecat-shared-vault-secrets/README.md) for full setup
details, secret-id rotation procedure, and error reference.

## Test plan

- [x] 54 unit tests passing (including 3 new bootstrapPath
auto-resolution tests)
- [x] 100% statement/function/line coverage
- [x] Two rounds of crew review (security, architecture, code quality) -
all must-fix items addressed
- [x] Lint clean
- [x] E2E validated on real Lambda (SM bootstrap -> AppRole auth ->
Vault KV read)
- [x] CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants