-
Notifications
You must be signed in to change notification settings - Fork 191
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
Bug 1862426: gather the audit logs for oauth apiserver #144
Changes from all commits
7701ea2
9ba1a64
7b3fff5
d3bd409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
#!/bin/bash | ||
BASE_COLLECTION_PATH="/must-gather" | ||
AUDIT_LOG_PATH="${BASE_COLLECTION_PATH}/audit_logs/" | ||
|
||
### Helper Functions | ||
function queue() { | ||
local TARGET="${1}" | ||
shift | ||
local LIVE="$(jobs | wc -l)" | ||
while [[ "${LIVE}" -ge 45 ]]; do | ||
sleep 1 | ||
LIVE="$(jobs | wc -l)" | ||
done | ||
echo "${@}" | ||
if [[ -n "${FILTER}" ]]; then | ||
"${@}" | "${FILTER}" >"${TARGET}" & | ||
else | ||
"${@}" >"${TARGET}" & | ||
fi | ||
} | ||
|
||
# Collect System Audit Logs | ||
function collect_audit_logs { ### Takes an input of PATH | ||
### (openshift-apiserver or kube-apiserver) | ||
|
||
echo "WARNING: Collecting one or more audit logs on ALL masters in your cluster. This could take a large amount of time." >&2 | ||
mkdir -p ${AUDIT_LOG_PATH}/${1} | ||
/usr/bin/oc adm node-logs --role=master --path=${1}/ | grep -v ".terminating" > ${AUDIT_LOG_PATH}/${1}.audit_logs_listing | ||
while IFS=$'\n' read -r line; do | ||
IFS=' ' read -ra log <<< "${line}" | ||
FILTER=gzip queue ${AUDIT_LOG_PATH}/${1}/"${log[0]}"-"${log[1]}".gz /usr/bin/oc adm node-logs "${log[0]}" --path=${1}/"${log[1]}" | ||
done < ${AUDIT_LOG_PATH}/${1}.audit_logs_listing | ||
echo "INFO: Audit logs for $1 collected." | ||
} | ||
|
||
collect_audit_logs openshift-apiserver | ||
collect_audit_logs kube-apiserver | ||
# Downloads the audit.log (and its rotated copies) from | ||
# /var/logs/{kube-apiserver,openshift-apiserver} on each | ||
# master node. | ||
BASE_COLLECTION_PATH="${BASE_COLLECTION_PATH:-/must-gather}" | ||
echo "WARNING: Collecting one or more audit logs on ALL masters in your cluster. This could take a large amount of time." >&2 | ||
# the command executed by xargs below expects four parameters: | ||
# $1 - node path under /var/logs to download | ||
# $2 - local output path | ||
# $3 - node name | ||
# $4 - log file name | ||
paths=(openshift-apiserver kube-apiserver oauth-apiserver) | ||
for path in "${paths[@]}" ; do | ||
output_dir="${BASE_COLLECTION_PATH}/audit_logs/$path" | ||
mkdir -p "$output_dir" | ||
oc adm node-logs --role=master --path="$path" | \ | ||
tee "${BASE_COLLECTION_PATH}/audit_logs/$path.audit_logs_listing" | \ | ||
grep -v ".terminating" | \ | ||
sed "s|^|$path $output_dir |" | ||
done | \ | ||
xargs --max-args=4 --max-procs=45 bash -c \ | ||
'echo "INFO: Started downloading $1/$4 from $3"; | ||
oc adm node-logs $3 --path=$1/$4 | gzip > $2/$3-$4.gz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sferich888 , I have added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What other ways can we limit the collection? Is an awk script needed?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sferich888 I think I can work something out, but as a followup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In others scripts I see the full path of command, like:/usr/bin/oc |
||
echo "INFO: Finished downloading $1/$4 from $3"' \ | ||
bash | ||
echo "INFO: Audit logs collected." | ||
|
||
# force disk flush to ensure that all data gathered is accessible in the copy container | ||
sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't do this until the e2e test works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that e2e you're talking about already explicitly calls this script see https://github.com/openshift/origin/blob/1a83021f4dbc91de606a71d3a27cd80664aae26c/test/extended/cli/mustgather.go#L160 so it shouldn't block this PR