Skip to content

ingress access logging toggle added #216

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions scripts/CEE/ingress-access-logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Ingress Access Logging Toggle Script

## Purpose

This script executes enables/disables the ingress access logging.

## Parameters and Usage

### Usage

```bash
ocm backplane managedjob create CEE/ingress-access-logging -p ACCESS_LOGGING=enable
```

### Parameters
- INGRESS_ACCESS_LOGGING(enable|disable): toggle to enable/disable ingress access logging
25 changes: 25 additions & 0 deletions scripts/CEE/ingress-access-logging/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
file: script.sh
name: ingress-access-logging
description: Enables/Disables ingress access logging.
author: alvolkov
allowedGroups:
- SREP
- CEE
- LPSRE
rbac:
roles:
- namespace: "openshift-ingress-operator"
rules:
- verbs:
- "get"
- "patch"
apiGroups:
- "operator.openshift.io"
resources:
- "ingresscontrollers"
envs:
- key: ACCESS_LOGGING
description: Enable/Disable toggle for access logging.
optional: false
language: bash
customerDataAccess: false
64 changes: 64 additions & 0 deletions scripts/CEE/ingress-access-logging/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Toggle ingress access logging on OpenShift 4.14+
# Reference: https://docs.openshift.com/container-platform/4.14/networking/ingress-operator.html#nw-configure-ingress-access-logging_configuring-ingress

set -e
set -o nounset
set -o pipefail

INGRESS_NAME="default"
INGRESS_NAMESPACE="openshift-ingress-operator"

check_access_logging_status() {
echo "Verifying current access logging configuration..."
oc get ingresscontroller "$INGRESS_NAME" -n "$INGRESS_NAMESPACE" -o json | jq -r '
if .spec.logging.access.destination.type then
"Access logging is ENABLED (type: \(.spec.logging.access.destination.type), format: \(.spec.logging.access.httpLogFormat))"
else
"Access logging is DISABLED"
end
'
}

enable_access_logging() {
echo "Enabling ingress access logging..."
oc patch ingresscontroller "$INGRESS_NAME" -n "$INGRESS_NAMESPACE" --type=merge -p '{
"spec": {
"logging": {
"access": {
"destination": {
"type": "Container"
},
"httpLogFormat": "json"
}
}
}
}'
echo "Access logging enabled."
}

disable_access_logging() {
echo "Disabling ingress access logging..."
oc patch ingresscontroller "$INGRESS_NAME" -n "$INGRESS_NAMESPACE" --type=json -p='[
{"op": "remove", "path": "/spec/logging"}
]'
echo "Access logging disabled."
}

main() {
if [[ -z "${ACCESS_LOGGING}" || ( "$ACCESS_LOGGING" != "enable" && "$ACCESS_LOGGING" != "disable" ) ]]; then
echo "Error: ACCESS_LOGGING must be set to 'enable' or 'disable'"
exit 1
fi

if [[ "$ACCESS_LOGGING" == "enable" ]]; then
enable_access_logging
else
disable_access_logging
fi

check_access_logging_status
}

main