Skip to content
Open
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
312 changes: 156 additions & 156 deletions helpers/google/api.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions plugins/google/cloudfunctionsv2/cloudFunctionV2HttpsOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ module.exports = {
functions.data.forEach(funct => {
if (!funct.name) return;

if (!funct.environment || funct.environment !== 'GEN_2') return;
if (!funct.buildConfig || !funct.buildConfig.functionTarget) return;

let serviceConfig = funct.serviceConfig || {};
let triggerType = funct.template && funct.template.annotations ? funct.template.annotations['cloudfunctions.googleapis.com/trigger-type'] : null;

if (serviceConfig.uri) {
if (serviceConfig.securityLevel && serviceConfig.securityLevel == 'SECURE_ALWAYS') {
if (triggerType === 'HTTP_TRIGGER' || funct.uri) {
if (funct.uri && funct.uri.startsWith('https://')) {
helpers.addResult(results, 0,
'Cloud Function is configured to require HTTPS for HTTP invocations', region, funct.name);
} else {
Expand Down
79 changes: 39 additions & 40 deletions plugins/google/cloudfunctionsv2/cloudFunctionV2HttpsOnly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,56 @@ var plugin = require('./cloudFunctionV2HttpsOnly');

const functions = [
{
"name": "projects/my-test-project/locations/us-central1/functions/function-1",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-1",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"template": {
"annotations": {
"cloudfunctions.googleapis.com/trigger-type": "HTTP_TRIGGER"
}
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"uri": "https://us-central1-my-test-project.cloudfunctions.net/function-1",
"securityLevel": "SECURE_OPTIONAL"
"uri": "http://us-central1-my-test-project.cloudfunctions.net/function-1",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-2",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-2",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"template": {
"annotations": {
"cloudfunctions.googleapis.com/trigger-type": "HTTP_TRIGGER"
}
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"uri": "https://us-central1-my-test-project.cloudfunctions.net/function-2",
"securityLevel": "SECURE_ALWAYS"
"uri": "https://us-central1-my-test-project.cloudfunctions.net/function-2",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-3",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "handleEvent"
"name": "projects/my-test-project/locations/us-central1/services/function-3",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"template": {
"annotations": {
"cloudfunctions.googleapis.com/trigger-type": "EVENT_TRIGGER"
}
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com"
"buildConfig": {
"functionTarget": "handleEvent"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-4",
"environment": "GEN_1",
"state": "ACTIVE",
"runtime": "nodejs14",
"httpsTrigger": {
"url": "https://us-central1-my-test-project.cloudfunctions.net/function-4",
"securityLevel": "SECURE_OPTIONAL"
"name": "projects/my-test-project/locations/us-central1/services/regular-service",
"labels": {
"app": "my-app"
}
}
];
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('httpTriggerRequireHttps', function () {
plugin.run(cache, {}, callback);
});

it('should not check Gen 1 functions in v2 API response', function (done) {
it('should not check non-Cloud Functions services in Cloud Run API response', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(0);
done();
Expand All @@ -174,4 +174,3 @@ describe('httpTriggerRequireHttps', function () {

})
});

Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ module.exports = {
functions.data.forEach(func => {
if (!func.name) return;

if (!func.environment || func.environment !== 'GEN_2') return;
if (!func.buildConfig || !func.buildConfig.functionTarget) return;

let ingressSettings = func.serviceConfig && func.serviceConfig.ingressSettings
? func.serviceConfig.ingressSettings
: null;
let ingressSettings = func.ingress || null;

if (ingressSettings && ingressSettings.toUpperCase() == 'ALLOW_ALL') {
if (ingressSettings && ingressSettings.toUpperCase() == 'INGRESS_TRAFFIC_ALL') {
helpers.addResult(results, 2,
'Cloud Function is configured to allow all traffic', region, func.name);
} else if (ingressSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,43 @@ var plugin = require('./cloudFunctionV2IngressSettings');

const functions = [
{
"name": "projects/my-test-project/locations/us-central1/functions/function-1",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-1",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"ingressSettings": "ALLOW_ALL"
"ingress": "INGRESS_TRAFFIC_ALL",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-2",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-2",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"ingressSettings": "ALLOW_INTERNAL_AND_GCLB"
"ingress": "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-3",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-3",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com"
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-4",
"environment": "GEN_1",
"state": "ACTIVE",
"runtime": "nodejs14",
"ingressSettings": "ALLOW_ALL"
"name": "projects/my-test-project/locations/us-central1/services/regular-service",
"labels": {
"app": "my-app"
},
"ingress": "INGRESS_TRAFFIC_ALL"
}
];

Expand Down Expand Up @@ -153,7 +144,7 @@ describe('ingressAllTrafficDisabled', function () {
plugin.run(cache, {}, callback);
});

it('should not check Gen 1 functions in v2 API response', function (done) {
it('should not check non-Cloud Functions services in Cloud Run API response', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(0);
done();
Expand All @@ -168,5 +159,4 @@ describe('ingressAllTrafficDisabled', function () {
});

})
});

});
8 changes: 5 additions & 3 deletions plugins/google/cloudfunctionsv2/cloudFunctionV2LabelsAdded.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ module.exports = {
functions.data.forEach(func => {
if (!func.name) return;

if (!func.environment || func.environment !== 'GEN_2') return;
if (!func.buildConfig || !func.buildConfig.functionTarget) return;

if (func.labels && Object.keys(func.labels).length) {
let userLabels = func.labels ? Object.keys(func.labels).filter(key => !key.startsWith('goog-')) : [];

if (userLabels.length) {
helpers.addResult(results, 0,
`${Object.keys(func.labels).length} labels found for Cloud Function`, region, func.name);
`${userLabels.length} labels found for Cloud Function`, region, func.name);
} else {
helpers.addResult(results, 2,
'Cloud Function does not have any labels', region, func.name);
Expand Down
54 changes: 27 additions & 27 deletions plugins/google/cloudfunctionsv2/cloudFunctionV2LabelsAdded.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@ var plugin = require('./cloudFunctionV2LabelsAdded');

const functions = [
{
"name": "projects/my-test-project/locations/us-central1/functions/function-1",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-1",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20"
},
"template": {
"serviceAccount": "test@test-project.iam.gserviceaccount.com"
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"ingressSettings": "ALLOW_ALL"
"ingress": "INGRESS_TRAFFIC_ALL",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-2",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
"name": "projects/my-test-project/locations/us-central1/services/function-2",
"labels": {
"goog-managed-by": "cloudfunctions",
"goog-cloudfunctions-runtime": "nodejs20",
"deployment-tool": "console-cloud",
"env": "production"
},
"serviceConfig": {
"serviceAccountEmail": "test@test-project.iam.gserviceaccount.com",
"ingressSettings": "ALLOW_INTERNAL_AND_GCLB"
"template": {
"serviceAccount": "test@test-project.iam.gserviceaccount.com"
},
"labels": { 'deployment-tool': 'console-cloud', 'env': 'production' }
"ingress": "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER",
"buildConfig": {
"functionTarget": "helloHttp"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-3",
"environment": "GEN_1",
"state": "ACTIVE",
"runtime": "nodejs14",
"ingressSettings": "ALLOW_ALL"
"name": "projects/my-test-project/locations/us-central1/services/regular-service",
"labels": {
"app": "my-app"
}
}
];

Expand Down Expand Up @@ -124,7 +124,7 @@ describe('cloudFunctionLabelsAdded', function () {
plugin.run(cache, {}, callback);
});

it('should not check Gen 1 functions in v2 API response', function (done) {
it('should not check non-Cloud Functions services in Cloud Run API response', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(0);
done();
Expand Down
5 changes: 2 additions & 3 deletions plugins/google/cloudfunctionsv2/cloudFunctionV2OldRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ module.exports = {
functions.data.forEach(func => {
if (!func.name) return;

if (!func.environment || func.environment !== 'GEN_2') return;
if (!func.buildConfig || !func.buildConfig.functionTarget) return;

let buildConfig = func.buildConfig || {};
let runtime = buildConfig.runtime;
let runtime = func.labels && func.labels['goog-cloudfunctions-runtime'] ? func.labels['goog-cloudfunctions-runtime'] : null;

if (!runtime) {
helpers.addResult(results, 2,
Expand Down
Loading