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

Force HTTPS in newly created v1 functions #3923

Merged
merged 1 commit into from Nov 30, 2021
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
@@ -1,2 +1,3 @@
- Corrects a bug where containers in Artifact Registry would not be deleted if a function has an upper case character in its name
- Fixes issue where providing the `--project` flag during `init` would not be recognized with a default project already set. (#3870)
- New HTTPS functions only allow secure traffic.
6 changes: 6 additions & 0 deletions src/deploy/functions/release/fabricator.ts
Expand Up @@ -205,6 +205,12 @@ export class Fabricator {
throw new Error("Precondition failed");
}
const apiFunction = gcf.functionFromEndpoint(endpoint, this.sourceUrl);
// As a general security practice and way to smooth out the upgrade path
// for GCF gen 2, we are enforcing that all new GCFv1 deploys will require
// HTTPS
if (apiFunction.httpsTrigger) {
apiFunction.httpsTrigger.securityLevel = "SECURE_ALWAYS";
}
apiFunction.sourceToken = await scraper.tokenPromise();
const resultFunction = await this.functionExecutor
.run(async () => {
Expand Down
14 changes: 14 additions & 0 deletions src/test/deploy/functions/release/fabricator.spec.ts
Expand Up @@ -136,6 +136,20 @@ describe("Fabricator", () => {
).to.be.rejectedWith(reporter.DeploymentError, "set invoker");
});

it("enforces SECURE_ALWAYS HTTPS policies", async () => {
gcf.createFunction.resolves({ name: "op", type: "create", done: false });
poller.pollOperation.resolves();
gcf.setInvokerCreate.resolves();
const ep = endpoint();

await fab.createV1Function(ep, new scraper.SourceTokenScraper());
expect(gcf.createFunction).to.have.been.calledWithMatch({
httpsTrigger: {
securityLevel: "SECURE_ALWAYS",
},
});
});

it("sets invoker by default", async () => {
gcf.createFunction.resolves({ name: "op", type: "create", done: false });
poller.pollOperation.resolves();
Expand Down