Skip to content

Commit 22e22e6

Browse files
committed
fix(COD-6066): hide the Lacework credentials from the running commands
1 parent 7813866 commit 22e22e6

5 files changed

Lines changed: 25 additions & 26 deletions

File tree

.github/workflows/integration-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
workflow_dispatch:
1111

1212
env:
13-
LW_ACCOUNT_NAME: ${{ secrets.LW_ACCOUNT_CAT }}
13+
LW_ACCOUNT: ${{ secrets.LW_ACCOUNT_CAT }}
1414
LW_API_KEY: ${{ secrets.LW_API_KEY_CAT }}
1515
LW_API_SECRET: ${{ secrets.LW_API_SECRET_CAT }}
1616
DEBUG: true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ permissions:
2323
pull-requests: write
2424

2525
env:
26-
LW_ACCOUNT_NAME: ${{ secrets.LW_ACCOUNT_NAME }}
27-
LW_SUBACCOUNT_NAME: ${{ secrets.LW_SUBACCOUNT_NAME }}
26+
LW_ACCOUNT: ${{ secrets.LW_ACCOUNT }}
27+
LW_SUBACCOUNT: ${{ secrets.LW_SUBACCOUNT }}
2828
LW_API_KEY: ${{ secrets.LW_API_KEY }}
2929
LW_API_SECRET: ${{ secrets.LW_API_SECRET }}
3030

action.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ runs:
6969
if: ${{ inputs.debug == 'true' }}
7070
run: |
7171
echo "LW_LOG=debug" >> $GITHUB_ENV
72+
- name: Set Lacework account environment variable
73+
shell: bash
74+
run: |
75+
if [ -z "${{ env.LW_ACCOUNT_NAME }}" ]; then
76+
echo "LW_ACCOUNT=${{ env.LW_ACCOUNT_NAME }}" >> $GITHUB_ENV
77+
fi
7278
- name: Install Lacework CLI component
7379
shell: bash
7480
run: |
75-
lacework --noninteractive -a "${LW_ACCOUNT_NAME}" -k "${LW_API_KEY}" -s "${LW_API_SECRET}" component install sca
76-
lacework --noninteractive -a "${LW_ACCOUNT_NAME}" -k "${LW_API_KEY}" -s "${LW_API_SECRET}" version
81+
lacework --noninteractive component install sca
82+
lacework --noninteractive version
7783
env:
7884
CDK_DOWNLOAD_TIMEOUT_MINUTES: 2
7985
- uses: actions/setup-node@v4

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ async function runAnalysis() {
4141
await callLaceworkCli(...args)
4242
toUpload.push(sarifReportPath)
4343

44-
const uploadStart = Date.now()
45-
4644
await uploadArtifact(getArtifactName(target), ...toUpload)
4745
setOutput(`${target}-completed`, true)
4846
}

src/util.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export function getRunUrl(): string {
3131
}
3232

3333
export async function callCommand(command: string, ...args: string[]) {
34+
// // set LW_ACCOUNT for backwards compatibility
35+
// let env = { ...process.env }
36+
// const lwAccountName = getOptionalEnvVariable('LW_ACCOUNT_NAME', '')
37+
// if (lwAccountName !== '') {
38+
// env.LW_ACCOUNT = lwAccountName
39+
// }
3440
info('Invoking ' + command + ' ' + args.join(' '))
3541
const child = spawn(command, args, { stdio: 'inherit' })
3642
const exitCode = await new Promise((resolve, _) => {
@@ -51,6 +57,10 @@ export function getRequiredEnvVariable(name: string) {
5157
return value
5258
}
5359

60+
export function setEnvironmentVariable(name: string, value: string) {
61+
process.env[name] = value
62+
}
63+
5464
export function getOptionalEnvVariable(name: string, defaultValue: string) {
5565
const value = process.env[name]
5666
if (!value) {
@@ -60,22 +70,7 @@ export function getOptionalEnvVariable(name: string, defaultValue: string) {
6070
}
6171

6272
export async function callLaceworkCli(...args: string[]) {
63-
const accountName = getRequiredEnvVariable('LW_ACCOUNT_NAME')
64-
const apiKey = getRequiredEnvVariable('LW_API_KEY')
65-
const apiSecret = getRequiredEnvVariable('LW_API_SECRET')
66-
const expandedArgs = [
67-
'--noninteractive',
68-
'--account',
69-
accountName,
70-
'--api_key',
71-
apiKey,
72-
'--api_secret',
73-
apiSecret,
74-
'sca',
75-
...args,
76-
]
77-
info('Calling lacework ' + expandedArgs.join(' '))
78-
await callCommand('lacework', ...expandedArgs)
73+
await callCommand('lacework', '--noninteractive', 'sca', ...args)
7974
}
8075

8176
export function getOrDefault(name: string, defaultValue: string) {
@@ -93,7 +88,7 @@ export function generateUILink() {
9388

9489
if (targetBranch !== defaultBranch) return ''
9590

96-
let lwAccountName = process.env.LW_ACCOUNT_NAME
91+
let lwAccountName = process.env.LW_ACCOUNT
9792
lwAccountName = lwAccountName?.replace(/\.lacework\.net$/, '')
9893

9994
let url =
@@ -102,8 +97,8 @@ export function generateUILink() {
10297
`github.com%2F${context.repo.owner}%2F${context.repo.repo}` +
10398
`/${defaultBranch}`
10499

105-
if (process.env.LW_SUBACCOUNT_NAME) {
106-
url += '?accountName=' + process.env.LW_SUBACCOUNT_NAME
100+
if (process.env.LW_SUBACCOUNT) {
101+
url += '?accountName=' + process.env.LW_SUBACCOUNT
107102
}
108103

109104
return url

0 commit comments

Comments
 (0)