Skip to content

Commit

Permalink
Force HTTPS in newly created v1 functions (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
inlined committed Nov 30, 2021
1 parent 418f11c commit 5951900
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit 5951900

Please sign in to comment.