forked from Normation/rudder-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
145 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
# Shellcheck | ||
find . -path ./.git -prune -o -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; -print | | ||
while IFS="" read -r file | ||
do | ||
# with recent shellcheck, "-S error" replaces this hack | ||
shellcheck -f gcc "$file" | grep " error: " && exit 1 || true | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# signs reports | ||
|
||
if [ -f "${RUDDER_JSON}" ]; then | ||
DAVUSER=$(rudder_json_value 'DAVUSER') | ||
DAVPW=$(rudder_json_value 'DAVPASSWORD') | ||
fi | ||
|
||
SERVER=$(cat "${RUDDER_VAR}/cfengine-community/policy_server.dat") | ||
TMP_REPORTS_DIR="/var/rudder/tmp/reports/" | ||
REPORTS_DIR="/var/rudder/reports/ready/" | ||
|
||
mkdir -p "${TMP_REPORTS_DIR}" | ||
mkdir -p "${REPORTS_DIR}" | ||
|
||
# The key to use for signature | ||
PRIVKEY="/var/rudder/cfengine-community/ppkeys/localhost.priv" | ||
CERT="/opt/rudder/etc/ssl/agent.cert" | ||
|
||
# Private key passphrase | ||
PASSPHRASE="Cfengine passphrase" | ||
|
||
# Should be called on the output file from temp directory | ||
# Everything in the ready dir should be ready to be sent | ||
compress_and_sign() { | ||
# filename | ||
file="$1" | ||
tmp_file="${TMP_REPORTS_DIR}/${file}" | ||
ready_file="${REPORTS_DIR}/${file}.gz" | ||
|
||
# We do not include certs as the server already knows them | ||
openssl smime -sign -text -nocerts -signer "${CERT}" -inkey "${PRIVKEY}" -passin "pass:${PASSPHRASE}" \ | ||
-in "${tmp_file}" -out "${tmp_file}.signed" | ||
if [ $? -eq 0 ]; then | ||
# Move temp file | ||
mv "${tmp_file}.signed" "${tmp_file}" | ||
else | ||
echo "${red}error${normal}: ${tmp_file} could not be signed" | ||
rm -f "${tmp_file}.signed" | ||
exit 1 | ||
fi | ||
|
||
gzip -f "${tmp_file}" | ||
if [ $? -ne 0 ]; then | ||
echo "${red}error${normal}: Could not compress ${tmp_file}, exiting" | ||
return 1 | ||
fi | ||
|
||
# (Very likely) atomic move in ready reports dir | ||
mv "${tmp_file}.gz" "${ready_file}" | ||
|
||
# Try to send it. | ||
# If it fails, it will be sent later by the agent | ||
curl --tlsv1.2 --insecure --fail --silent --proxy '' --user "${DAVUSER}:${DAVPW}" --upload-file "${ready_file}" https://${SERVER}/reports/ | ||
if [ $? -eq 0 ]; then | ||
# Remove temp file | ||
rm "${ready_file}" | ||
else | ||
# Keep the runlog for future upload by the agent | ||
echo "${yellow}warning${normal}: Could not send ${ready_file}, it will be retried later" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
|
||
# Timestamps all lines | ||
while IFS= read -r line; do | ||
# Same as in agent with a T instead of space (iso8601 UTC) | ||
date=$(/bin/date -u "+%Y-%m-%dT%T+00:00") | ||
printf "${date} %s\n" "$line" | ||
done |