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

Correctly copy over secret environment variables #4543

Merged
merged 4 commits into from May 11, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
- Fixes bug where secret environment variables were not set on functions (#4543)
29 changes: 18 additions & 11 deletions src/deploy/functions/runtimes/discovery/v1alpha1.ts
Expand Up @@ -13,7 +13,14 @@ const CHANNEL_NAME_REGEX = new RegExp(
"(?<channel>[A-Za-z\\d\\-_]+)"
);

export type ManifestEndpoint = backend.ServiceConfiguration &
export interface ManifestSecretEnv {
key: string;
secret?: string;
projectId: string;
}

type Base = Omit<backend.ServiceConfiguration, "secretEnvironmentVariables">;
export type ManifestEndpoint = Base &
backend.Triggered &
Partial<backend.HttpsTriggered> &
Partial<backend.CallableTriggered> &
Expand All @@ -24,6 +31,7 @@ export type ManifestEndpoint = backend.ServiceConfiguration &
region?: string[];
entryPoint: string;
platform?: backend.FunctionsPlatform;
secretEnvironmentVariables?: Array<ManifestSecretEnv>;
};

export interface Manifest {
Expand Down Expand Up @@ -249,17 +257,16 @@ function parseEndpoints(
ep,
"secretEnvironmentVariables",
"secretEnvironmentVariables",
(senvs: ManifestEndpoint["secretEnvironmentVariables"]) => {
if (senvs && senvs.length > 0) {
ep.secretEnvironmentVariables = [];
for (const { key, secret } of senvs) {
ep.secretEnvironmentVariables.push({
key,
secret: secret || key, // if secret is undefined, assume env var key == secret name
projectId: project,
});
}
(senvs: Array<ManifestSecretEnv>) => {
const secretEnvironmentVariables: backend.SecretEnvVar[] = [];
for (const { key, secret } of senvs) {
secretEnvironmentVariables.push({
key,
secret: secret || key, // if secret is undefined, assume env var key == secret name
projectId: project,
});
}
return secretEnvironmentVariables;
}
);
allParsed.push(parsed);
Expand Down
19 changes: 18 additions & 1 deletion src/test/deploy/functions/runtimes/discovery/v1alpha1.spec.ts
Expand Up @@ -294,7 +294,10 @@ describe("backendFromV1Alpha1", () => {
}); // Parser errors;

describe("allows valid backends", () => {
const DEFAULTED_ENDPOINT: Omit<backend.Endpoint, "httpsTrigger"> = {
const DEFAULTED_ENDPOINT: Omit<
backend.Endpoint,
"httpsTrigger" | "secretEnvironmentVariables"
> = {
...MIN_ENDPOINT,
platform: "gcfv2",
id: "id",
Expand Down Expand Up @@ -551,6 +554,13 @@ describe("backendFromV1Alpha1", () => {
},
ingressSettings: "ALLOW_INTERNAL_ONLY",
serviceAccountEmail: "sa@",
secretEnvironmentVariables: [
{
key: "SECRET",
secret: "SECRET",
projectId: "project",
},
],
};

const yaml: v1alpha1.Manifest = {
Expand All @@ -560,6 +570,13 @@ describe("backendFromV1Alpha1", () => {
...MIN_ENDPOINT,
httpsTrigger: {},
...fields,
secretEnvironmentVariables: [
{
key: "SECRET",
// Missing "secret"
projectId: "project",
},
],
},
},
};
Expand Down