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

Fix secret vuln #200

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 0 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ jobs:
id: plan
working-directory: terraform
run: terraform plan -out tfplan
env:
TF_VAR_app_id: ${{ secrets.APP_ID }}
TF_VAR_webhook_secret: ${{ secrets.WEBHOOK_SECRET }}
TF_VAR_private_key: ${{ secrets.PRIVATE_KEY }}
TF_VAR_gputester_pat: ${{ secrets.GPUTESTER_PAT }}

- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ terraform plan
terraform apply
```

### Required Environment Variables

- `APP_ID`: GitHub App ID
- `WEBHOOK_SECRET`: GitHub Webhook Secret
- `PRIVATE_KEY`: GitHub App Private Key
- `GPUTESTER_PAT`: GPU Tester Personal Access Token

## npm Scripts

```sh
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
export default {
roots: ['<rootDir>/src/', '<rootDir>/test/'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.[tj]sx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coveragePathIgnorePatterns: ["/node_modules/", "test/"],
coveragePathIgnorePatterns: ["/node_modules/", "test/"]
}
2,316 changes: 2,232 additions & 84 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "ops-bot",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "RAPIDS Probot App",
"author": "AJ Schmidt <[email protected]>",
"license": "ISC",
Expand All @@ -23,6 +24,7 @@
"dependencies": {
"@aws-sdk/client-lambda": "^3.398.0",
"@probot/adapter-aws-lambda-serverless": "^3.0.3",
"@aws-sdk/client-secrets-manager": "^3.712.0",
"axios": "^1.5.0",
"nunjucks": "^3.2.4",
"probot": "^12.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { initRecentlyUpdated } from "./plugins/RecentlyUpdated";
import { initReleaseDrafter } from "./plugins/ReleaseDrafter";
import { initForwardMerger } from "./plugins/ForwardMerger";

export = (app: Probot) => {
export default (app: Probot) => {
initBranchChecker(app);
initLabelChecker(app);
initReleaseDrafter(app);
Expand Down
44 changes: 43 additions & 1 deletion src/probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,49 @@ import {
createProbot,
} from "@probot/adapter-aws-lambda-serverless";
import app from "./index";
import {
GetSecretValueCommand,
SecretsManagerClient,
} from "@aws-sdk/client-secrets-manager";
import { getPrivateKey } from "@probot/get-private-key";

// get the secrets here and add it to the createProbot function as overrides
const retreiveCredentials = async () => {
const client = new SecretsManagerClient({
region: "us-east-2",
retryMode: "standard",
maxAttempts: 3,
});
const input = {
SecretId:
"arn:aws:secretsmanager:us-east-2:279114543810:secret:lambda/ops-bot-handleProbot-qlVFbZ",
};
const command = new GetSecretValueCommand(input);
const { SecretString } = await client.send(command);
if (typeof SecretString !== "string") {
throw new Error("Error getting secrets");
}
const obj = JSON.parse(SecretString) as {
webhookSecret: string;
privateKey: string;
appId: number;
gputesterPat: string;
};

process.env.GPUTESTER_PAT = obj.gputesterPat;

return {
secret: obj.webhookSecret,
// This decodes an optionally base64-encoded private key
privateKey: getPrivateKey({
env: { PRIVATE_KEY: obj.privateKey },
})!,
appId: obj.appId,
};
};

const { secret, privateKey, appId } = await retreiveCredentials();

export const handler = createLambdaFunction(app, {
probot: createProbot(),
probot: createProbot({overrides: {secret, privateKey, appId}}),
});
10 changes: 3 additions & 7 deletions terraform/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ resource "aws_lambda_function" "probot_handler" {

environment {
variables = {
NODE_ENV = "production"
LOG_FORMAT = "json"
LOG_LEVEL = "debug"
APP_ID = var.app_id
WEBHOOK_SECRET = var.webhook_secret
PRIVATE_KEY = var.private_key
GPUTESTER_PAT = var.gputester_pat
NODE_ENV = "production"
LOG_FORMAT = "json"
LOG_LEVEL = "debug"
}
}

Expand Down
24 changes: 0 additions & 24 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,3 @@ variable "aws_region" {
type = string
default = "us-east-2"
}

variable "app_id" {
description = "GitHub App ID"
type = string
sensitive = true
}

variable "webhook_secret" {
description = "GitHub Webhook Secret"
type = string
sensitive = true
}

variable "private_key" {
description = "GitHub App Private Key"
type = string
sensitive = true
}

variable "gputester_pat" {
description = "GPU Tester PAT"
type = string
sensitive = true
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
/* Basic Options */
"incremental": true /* Enable incremental compilation */,
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"target": "es2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"es2015",
"es2017"
Expand Down
Loading