Skip to content
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

chore: switch to writeSecureFile from actions-utils #535

Merged
merged 1 commit into from
Mar 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/tool-cache": "^1.7.1",
"@google-github-actions/actions-utils": "^0.1.2",
"@google-github-actions/actions-utils": "^0.1.6",
"@google-github-actions/setup-cloud-sdk": "^0.5.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/setup-gcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
errorMessage,
isPinnedToHead,
pinnedToHeadWarning,
writeSecureFile,
} from '@google-github-actions/actions-utils';
import { writeSecureFile } from './utils';
import path from 'path';
import crypto from 'crypto';

Expand Down
18 changes: 0 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@

import { promises as fs } from 'fs';

/**
* writeSecureFile writes a file to disk in a given directory with a
* random name.
*
* @param outputPath Path in which to create random file in.
* @param data Data to write to file.
* @returns Path to written file.
*/
export async function writeSecureFile(
outputPath: string,
data: string,
): Promise<string> {
// Write the file as 0640 so the owner has RW, group as R, and the file is
// otherwise unreadable. Also write with EXCL to prevent a symlink attack.
await fs.writeFile(outputPath, data, { mode: 0o640, flag: 'wx' });
return outputPath;
}

/**
* removeExportedCredentials removes any exported credentials file. If the file
* does not exist, it does nothing.
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import { tmpdir } from 'os';
import crypto from 'crypto';
import path from 'path';

import { writeSecureFile } from '@google-github-actions/actions-utils';

import { removeExportedCredentials } from '../src/utils';
import { writeSecureFile } from '../src/utils';

describe('post', () => {
describe('#removeExportedCredentials', () => {
Expand Down