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

Fix configuration directory and file permissions #563

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 7 additions & 19 deletions scripts/includes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,22 @@ configure_st2_cli_config() {
CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2"
CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config"

if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then
sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${ROOT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Write config for root user
if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then
return
fi

# Write config for current user (in case current user != root)
if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then
sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${CURRENT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Fix the permissions
sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
}


Expand Down
26 changes: 7 additions & 19 deletions scripts/st2bootstrap-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -298,34 +298,22 @@ configure_st2_cli_config() {
CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2"
CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config"

if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then
sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${ROOT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Write config for root user
if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then
return
fi

# Write config for current user (in case current user != root)
if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then
sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${CURRENT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \
blag marked this conversation as resolved.
Show resolved Hide resolved
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Fix the permissions
sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
Copy link
Member

@arm4b arm4b Jun 21, 2018

Choose a reason for hiding this comment

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

Don't need to chown anymore.

Keep in mind that curl|bash installer is not idempotent and runs only once (first install), and so the config files/dirs are created with the correct permissions on first run making chown excessive in this case.

Backwards compatibility you mentioned should be guaranteed by st2 login functionality.
That's why we moved this permissions logic into st2 login itself, see: StackStorm/st2#4173

}


Expand Down
26 changes: 7 additions & 19 deletions scripts/st2bootstrap-el6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,22 @@ configure_st2_cli_config() {
CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2"
CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config"

if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then
sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${ROOT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Write config for root user
if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then
return
fi

# Write config for current user (in case current user != root)
if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then
sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${CURRENT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Fix the permissions
sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
}


Expand Down
26 changes: 7 additions & 19 deletions scripts/st2bootstrap-el7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,22 @@ configure_st2_cli_config() {
CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2"
CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config"

if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then
sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${ROOT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Write config for root user
if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then
return
fi

# Write config for current user (in case current user != root)
if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then
sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
fi

sudo sh -c "cat <<EOT > ${CURRENT_USER_CLI_CONFIG_PATH}
[credentials]
username = ${USERNAME}
password = ${PASSWORD}
EOT"
st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \
--write-password \
--username ${USERNAME} --password ${PASSWORD}

# Fix the permissions
sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY}
}


Expand Down