Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/credentials/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,11 @@ const FILE_ENV_POINTERS: Array<[RegExp, (abs: string) => string]> = [

export function renderUseScript(m: MaterializedCred): string {
if (m.kind === "env") return m.env.map((e) => `export ${e.key}=${shq(e.value)}`).join("\n") + "\n";
const lines = [`__kc_dir="$(mktemp -d "\${TMPDIR:-/tmp}/keychain.XXXXXX")"`, `umask 077`];
const lines = [
`__kc_dir="$(mktemp -d "\${TMPDIR:-/tmp}/keychain.XXXXXX")"`,
`umask 077`,
`trap 'rm -rf "$__kc_dir"' EXIT`,
];
for (const f of m.files) {
const parent = f.path.includes("/") ? f.path.replace(/\/[^/]*$/, "") : "";
if (parent) lines.push(`mkdir -p "$__kc_dir/${parent}"`);
Expand Down
1 change: 1 addition & 0 deletions test/keychain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ test("file bundles: one item per service, materialize to a /tmp script with env
assert.equal(m.kind, "file");
const script = renderUseScript(m);
assert.match(script, /mktemp -d/);
assert.match(script, /trap 'rm -rf "\$__kc_dir"' EXIT/);
assert.match(script, /chmod 600/);
assert.match(script, /export AWS_SHARED_CREDENTIALS_FILE="\$__kc_dir\/.aws\/credentials"/);
assert.ok(
Expand Down