Skip to content

Commit

Permalink
Merge pull request #328 from jmpsec/fix-provision-cli
Browse files Browse the repository at this point in the history
Fix `osctrl-cli` syntax
  • Loading branch information
javuto authored Dec 20, 2022
2 parents 2e7e90a + f3908a7 commit e8613c9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deploy/docker/conf/osctrl/cli/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ -n "$OSCTRL_PASS_FILE" ]]; then
fi

######################################### Wait until DB is up #########################################
until /opt/osctrl/bin/osctrl-cli check-db
until /opt/osctrl/bin/osctrl-cli --db check-db
do
echo "DB is not ready"
sleep $WAIT
Expand Down
4 changes: 2 additions & 2 deletions deploy/docker/conf/osquery/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ENV_NAME="${ENV_NAME:=dev}"
HOST="${HOST:=nginx}"

if [ ! -f "/etc/osquery/osquery.secret" ]; then
######################################### Wait until DB is up #########################################
until /opt/osctrl/bin/osctrl-cli check-db
######################################### Wait until DB is up #########################################
until /opt/osctrl/bin/osctrl-cli --db check-db
do
echo "DB is not ready"
sleep $WAIT
Expand Down
14 changes: 7 additions & 7 deletions deploy/docker/conf/osquery/wait-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@ _USER="${_USER:=admin}"
WAIT=${WAIT:=5}

# Wait until DB is up
until /opt/osctrl/bin/osctrl-cli -D "$DB_JSON" check
until /opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" check
do
echo "DB is not ready"
sleep $WAIT
done

# Create environment dev
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env add -name "$ENV_NAME" -host "$_HOST" -crt "$CRT_FILE"
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env add -name "$ENV_NAME" -host "$_HOST" -crt "$CRT_FILE"
if [ $? -eq 0 ]; then
echo "Created environment dev"
else
echo "Environment dev exists"
fi

# Decrease intervals in dev
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env update -n "$ENV_NAME" -l 75 -c 45 -q 60
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env update -n "$ENV_NAME" -l 75 -c 45 -q 60

# Enable verbose mode
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env add-osquery-option -n dev -o "verbose" -t bool -b true
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env add-osquery-option -n dev -o "verbose" -t bool -b true
# Disable splay for schedule
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env add-osquery-option -n dev -o "schedule_splay_percent" -t int -i 0
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env add-osquery-option -n dev -o "schedule_splay_percent" -t int -i 0
# Add uptime query to schedule
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env add-scheduled-query -n dev -q "SELECT * FROM uptime;" -Q "uptime" -i 60
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env add-scheduled-query -n dev -q "SELECT * FROM uptime;" -Q "uptime" -i 60

# Create admin user
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" user add -u "$_USER" -p "$_USER" -a -E "$ENV_NAME" -n "$_USER"
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" user add -u "$_USER" -p "$_USER" -a -E "$ENV_NAME" -n "$_USER"
if [ $? -eq 0 ]; then
echo "Created $_USER user"
else
Expand Down
8 changes: 4 additions & 4 deletions deploy/docker/conf/osquery/wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ ENV_NAME="dev"
WAIT=5

# Wait until DB is up
until /opt/osctrl/bin/osctrl-cli -D "$DB_JSON" check
until /opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" check
do
sleep $WAIT
done

# Wait until osctrl environment is up
until /opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env show --name "$ENV_NAME"
until /opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env show --name "$ENV_NAME"
do
sleep $WAIT
done

# To enroll, check existance for flags and secret and they are not empty
while [ ! -f "$FLAGS_FILE" ] && [ ! -s "$FLAGS_FILE" ] && [ ! -f "$SECRET_FILE" ] && [ ! -s "$SECRET_FILE" ];
do
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env secret --name "$ENV_NAME" > ${SECRET_FILE}
/opt/osctrl/bin/osctrl-cli -D "$DB_JSON" env show-flags --name "$ENV_NAME" | sed 's/=uuid/=ephemeral/g' > ${FLAGS_FILE}
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env secret --name "$ENV_NAME" > ${SECRET_FILE}
/opt/osctrl/bin/osctrl-cli --db -D "$DB_JSON" env show-flags --name "$ENV_NAME" | sed 's/=uuid/=ephemeral/g' > ${FLAGS_FILE}
sed -i "s#--enroll_secret_path=.*#--enroll_secret_path=${SECRET_FILE}#g" ${FLAGS_FILE}
sed -i "s#--enroll_secret_path=.*#--enroll_secret_path=${SECRET_FILE}#g" ${FLAGS_FILE}
sed -i "s#--distributed_interval=.*#--distributed_interval=60#g" ${FLAGS_FILE}
Expand Down
16 changes: 8 additions & 8 deletions deploy/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -736,27 +736,27 @@ else

# Create initial environment to enroll machines
log "Creating environment $ENVIRONMENT"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" environment add -n "$ENVIRONMENT" -host "$_T_HOST" -crt "$__osctrl_crt"
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment add -n "$ENVIRONMENT" -host "$_T_HOST" -crt "$__osctrl_crt"

# Create admin user
log "Creating admin user"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" user add -u "$_ADMIN_USER" -p "$_ADMIN_PASS" -a -E "$ENVIRONMENT" -n "Admin"
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" user add -u "$_ADMIN_USER" -p "$_ADMIN_PASS" -a -e "$ENVIRONMENT" -n "Admin"

# If we are in dev, lower intervals
if [[ "$MODE" == "dev" ]]; then
log "Decrease intervals for environment $ENVIRONMENT"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" environment update -n "$ENVIRONMENT" -l "75" -c "45" -q "60"
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment update -n "$ENVIRONMENT" -l "75" -c "45" -q "60"
log "Enable verbose mode"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" environment add-osquery-option -n "$ENVIRONMENT" -o "verbose" -t bool -b true
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment add-osquery-option -n "$ENVIRONMENT" -o "verbose" -t bool -b true
log "Disable splay for schedule"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" environment add-osquery-option -n "$ENVIRONMENT" -o "schedule_splay_percent" -t int -i 0
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment add-osquery-option -n "$ENVIRONMENT" -o "schedule_splay_percent" -t int -i 0
log "Add uptime query to schedule"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" environment add-scheduled-query -n "$ENVIRONMENT" -q "SELECT * FROM uptime;" -Q "uptime" -i 60
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment add-scheduled-query -n "$ENVIRONMENT" -q "SELECT * FROM uptime;" -Q "uptime" -i 60
fi

# Make newly created environment as default
log "Making environment $ENVIRONMENT as default"
"$DEST_PATH"/osctrl-cli -D "$__db_conf" settings add -n default_env -s admin --type string --string "$ENVIRONMENT"
"$DEST_PATH"/osctrl-cli --db -D "$__db_conf" settings add -n default_env -s admin --type string --string "$ENVIRONMENT"

log "Checking if service is ready"
while true; do
Expand All @@ -773,7 +773,7 @@ else
# Enroll host in environment
if [[ "$ENROLL" == true ]]; then
log "Adding host in environment $ENVIRONMENT"
eval $( "$DEST_PATH"/osctrl-cli -D "$__db_conf" environment quick-add -n "$ENVIRONMENT" )
eval $( "$DEST_PATH"/osctrl-cli --db -D "$__db_conf" environment quick-add -n "$ENVIRONMENT" )
fi

# Ascii art is always appreciated
Expand Down

0 comments on commit e8613c9

Please sign in to comment.