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

feat: add support for forbidding environment variables in gitops files #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion kp_pre_commit_hooks/gitops-values-validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

###############################################################################
# Main code
# Global Parameters
###############################################################################

SCHEMA_BASE_URL = "https://kp-helmchart-stable-shared-main.s3.eu-west-1.amazonaws.com/schema/platform-managed-chart"
Expand All @@ -32,6 +32,15 @@

TWINGATE_DOC_URL = "https://kpler.atlassian.net/wiki/spaces/KSD/pages/243562083/Install+and+configure+the+Twingate+VPN+client"

FORBIDDEN_ENVIRONMENT_VARIABLES = {
"KAFKA_APPLICATION_ID": """KAFKA_APPLICATION_ID is automatically set in your container and should not be overridden.
More info at https://kpler.atlassian.net/l/cp/jb4uJQs3#Use-connection-information-in-environment-variables""",
"KAFKA_BOOTSTRAP_SERVERS": """KAFKA_BOOSTRAP_SERVERS is automatically set in your container and should not be overridden.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yannrouillard there is a typo BOOSTRAP

More info at https://kpler.atlassian.net/l/cp/jb4uJQs3#Use-connection-information-in-environment-variables""",
"SCHEMA_REGISTRY_URL": """SCHEMA_REGISTRY_URL is automatically set in your container and should not be overridden.
More info at https://kpler.atlassian.net/l/cp/jb4uJQs3#Use-connection-information-in-environment-variables""",
}

###############################################################################
# Generic Helper functions and classes
###############################################################################
Expand Down Expand Up @@ -360,6 +369,16 @@ def validate_topic_name_compliance(self, value, schema):
if match and match["serviceName"] != service_name:
yield ValidationError(f"topicName '{value}' it not compliant, it should contain the service name '{service_name}'")

def validate_forbidden_environment_variables(self, value, schema):
if not isinstance(value, dict):
return
for env_variable, forbidden_reason in FORBIDDEN_ENVIRONMENT_VARIABLES.items():
if env_variable in value:
yield ValidationError(
f"Environment variable `{env_variable}` is not allowed to be manually set",
schema={"description": f"Remove `{env_variable}` from your environment variables.\n{forbidden_reason}"},
)


def format_error(error: Union[ValidationError, SchemaValidationError]):
if isinstance(error, SchemaValidationError):
Expand Down