@pulumi/kubernetes-compliance-policies
Version:
This repository contains a growing set of Compliance Policies to validate your infrastructure using Pulumi's Crossguard Policy-as-Code framework.
134 lines (133 loc) • 6.06 kB
JavaScript
;
// Copyright 2016-2024, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ------------------------------- WARNING -------------------------------------
// This file was programmatically generated. Do not edit unless you know what
// you're doing.
// ------------------------------- WARNING -------------------------------------
Object.defineProperty(exports, "__esModule", { value: true });
exports.Service = exports.Pod = void 0;
const v1_1 = require("@pulumi/kubernetes/core/v1");
const policy_1 = require("@pulumi/policy");
const compliance_policy_manager_1 = require("@pulumi/compliance-policy-manager");
const v1_2 = require("@pulumi/kubernetes/core/v1");
var Pod;
(function (Pod) {
/**
* Checks that Kubernetes Pods are not used directly.
*
* @severity critical
* @frameworks none
* @topics availability
* @link https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
*/
Pod.disallowPod = compliance_policy_manager_1.policyManager.registerPolicy({
resourceValidationPolicy: {
name: "kubernetes-core-v1-pod-disallow-pod",
description: "Checks that Kubernetes Pods are not used directly.",
configSchema: compliance_policy_manager_1.policyManager.policyConfigSchema,
enforcementLevel: "advisory",
validateResource: (0, policy_1.validateResourceOfType)(v1_1.Pod, (pod, args, reportViolation) => {
if (!compliance_policy_manager_1.policyManager.shouldEvalPolicy(args)) {
return;
}
reportViolation("Kubernetes Pods should not be used directly. Instead, you may want to use a Deployment, ReplicaSet, DaemonSet or Job.");
}),
},
vendors: ["kubernetes"],
services: ["core"],
severity: "critical",
topics: ["availability"],
});
})(Pod || (Pod = {}));
exports.Pod = Pod;
var Service;
(function (Service) {
/**
* Checks that Kubernetes Services use the recommended labels.
*
* @severity low
* @frameworks none
* @topics usability
* @link https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
*/
Service.configureRecommendedLabels = compliance_policy_manager_1.policyManager.registerPolicy({
resourceValidationPolicy: {
name: "kubernetes-core-v1-service-configure-recommended-labels",
description: "Checks that Kubernetes Services use the recommended labels.",
configSchema: compliance_policy_manager_1.policyManager.policyConfigSchema,
enforcementLevel: "advisory",
validateResource: (0, policy_1.validateResourceOfType)(v1_2.Service, (service, args, reportViolation) => {
var _a;
if (!compliance_policy_manager_1.policyManager.shouldEvalPolicy(args)) {
return;
}
if (!service.metadata || !service.metadata.labels) {
reportViolation("Kubernetes Services should use the recommended labels.");
}
else {
for (const key of Object.keys((_a = service.metadata) === null || _a === void 0 ? void 0 : _a.labels)) {
const recommendedLabels = [
"app.kubernetes.io/name",
"app.kubernetes.io/instance",
"app.kubernetes.io/version",
"app.kubernetes.io/component",
"app.kubernetes.io/part-of",
"app.kubernetes.io/managed-by",
];
if (recommendedLabels.indexOf(key) === -1) {
reportViolation("Kubernetes Services should have the recommended labels.");
}
}
}
}),
},
vendors: ["kubernetes"],
services: ["core"],
severity: "low",
topics: ["usability"],
});
/**
* Checks that Kubernetes Services do not use a LoadBalancer as service type.
*
* @severity low
* @frameworks none
* @topics cost, network
* @link https://github.com/datreeio/datree/blob/main/examples/Cost_Reduction/README.md
*/
Service.disallowLoadBalancer = compliance_policy_manager_1.policyManager.registerPolicy({
resourceValidationPolicy: {
name: "kubernetes-core-v1-service-disallow-load-balancer",
description: "Checks that Kubernetes Services do not use a LoadBalancer as service type.",
configSchema: compliance_policy_manager_1.policyManager.policyConfigSchema,
enforcementLevel: "advisory",
validateResource: (0, policy_1.validateResourceOfType)(v1_2.Service, (service, args, reportViolation) => {
if (!compliance_policy_manager_1.policyManager.shouldEvalPolicy(args)) {
return;
}
if (service.spec) {
if (service.spec.type && service.spec.type === "LoadBalancer") {
reportViolation("Kubernetes Services should not use a 'LoadBalancer' as a service type.");
}
}
}),
},
vendors: ["kubernetes"],
services: ["core"],
severity: "low",
topics: ["cost", "network"],
});
})(Service || (Service = {}));
exports.Service = Service;