Skip to content
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 src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Env {
// shared secret used as authorization when invoking the collab service (eg for syncadmin)
COLLAB_SHARED_SECRET: string;
DA_OPS_IMS_ORG: string;
DA_OPS_IMS_BOT_EMAIL: string;

DA_AUTH: KVNamespace,
DA_CONFIG: KVNamespace,
Expand Down
13 changes: 13 additions & 0 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ export async function getAclCtx(env, org, users, key, api) {
});
}

if (env.DA_OPS_IMS_BOT_EMAIL) {
props.permissions.data.push({
path: 'CONFIG',
groups: env.DA_OPS_IMS_BOT_EMAIL,
actions: 'write',
});
props.permissions.data.push({
path: '/ + **',
groups: env.DA_OPS_IMS_BOT_EMAIL,
actions: 'write',
});
}

const aclTrace = [];
props.permissions.data.forEach(({ path, groups, actions }) => {
if (!path || !groups) return;
Expand Down
39 changes: 39 additions & 0 deletions test/utils/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,45 @@ describe('DA auth', () => {
}, '/some/deep/path', 'write'));
});

it('test DA_OPS_IMS_BOT_EMAIL permissions', async () => {
const botEmail = 'da-ops-bot@adobe.com';
const envBot = {
...env2,
DA_OPS_IMS_BOT_EMAIL: botEmail,
};

// Bot user identified solely by email — no orgs membership at all.
// This is the substantive difference from the DA_OPS_IMS_ORG test:
// the bearer is matched on email, independent of IMS org membership.
const users = [{ email: botEmail, orgs: [] }];
const aclCtx = await getAclCtx(envBot, 'test', users, '/', 'config');

// Should have write permission on CONFIG because of DA_OPS_IMS_BOT_EMAIL injection
assert(hasPermission({
users, org: 'test', aclCtx, key: '',
}, 'CONFIG', 'write', true));

// Should have write permission on / because of DA_OPS_IMS_BOT_EMAIL injection
// (path: '/ + **')
assert(hasPermission({
users, org: 'test', aclCtx, key: '',
}, '/', 'write'));

// Should have write permission on path because of DA_OPS_IMS_BOT_EMAIL injection
// (path: '/ + **')
assert(hasPermission({
users, org: 'test', aclCtx, key: '',
}, '/some/deep/path', 'write'));

// A different email must NOT inherit bot permissions — the rule matches
// on the specific email, not on "any user when DA_OPS_IMS_BOT_EMAIL is set".
const otherUsers = [{ email: 'not-the-bot@adobe.com', orgs: [] }];
const otherCtx = await getAclCtx(envBot, 'test', otherUsers, '/', 'config');
assert(!hasPermission({
users: otherUsers, org: 'test', aclCtx: otherCtx, key: '',
}, '/', 'write'));
});

it('returns empty action set when DA_CONFIG KV GET throws 414 key-too-long error', async () => {
// IMS auth redirect fragments (access_token=..., ld_hash=...) leak into the URL path,
// producing an org segment >512 bytes. KV rejects the lookup with a 414 error;
Expand Down
Loading