Zitadel with Login V2 - Minor fixes following code review - #1428
Conversation
Greptile OverviewGreptile SummaryThis PR applies small follow-up fixes to the Zitadel CT setup and install scripts:
Main functional concern is systemd unit activation: the installer writes new unit files but no longer reloads systemd before enabling them, which can break fresh installs. Confidence Score: 2/5
Important Files Changed
|
| msg_info "Starting Service" | ||
| systemctl start zitadel | ||
| systemctl start zitadel-api | ||
| sleep 5 | ||
| systemctl start zitadel-login |
There was a problem hiding this comment.
Wrong service name
update_script now starts zitadel-api and zitadel-login, but it previously started zitadel and no longer starts a unit named zitadel. The install script only creates zitadel-api.service and zitadel-login.service, so starting zitadel will fail on existing installs unless a legacy zitadel.service still exists. Consider starting/stopping the same unit names consistently (e.g., zitadel-api.service / zitadel-login.service) to avoid failed updates on systems without a zitadel unit.
| msg_info "Create zitadel-rerun.sh" | ||
| cat <<EOF >~/zitadel-rerun.sh | ||
| systemctl stop zitadel | ||
| timeout --kill-after=5s 15s zitadel setup --masterkeyFile ${CONFIG_DIR}/.masterkey --config ${CONFIG_DIR}/config.yaml" | ||
| systemctl restart zitadel | ||
| systemctl stop zitadel-api zitadel-login | ||
| timeout --kill-after=5s 15s /opt/zitadel/zitadel setup --masterkeyFile ${CONFIG_DIR}/.masterkey --config ${CONFIG_DIR}/config.yaml | ||
| systemctl restart zitadel-api zitadel-login |
There was a problem hiding this comment.
Stray quote removed
In the generated ~/zitadel-rerun.sh, the old command had a trailing " which would make the script fail to run. The PR fixed it, but the heredoc currently writes a command without quoting paths/vars; if ${CONFIG_DIR} ever contains spaces (unlikely here) it would break. To keep it robust, quote the expanded paths in the heredoc.
| msg_info "Create zitadel-rerun.sh" | |
| cat <<EOF >~/zitadel-rerun.sh | |
| systemctl stop zitadel | |
| timeout --kill-after=5s 15s zitadel setup --masterkeyFile ${CONFIG_DIR}/.masterkey --config ${CONFIG_DIR}/config.yaml" | |
| systemctl restart zitadel | |
| systemctl stop zitadel-api zitadel-login | |
| timeout --kill-after=5s 15s /opt/zitadel/zitadel setup --masterkeyFile ${CONFIG_DIR}/.masterkey --config ${CONFIG_DIR}/config.yaml | |
| systemctl restart zitadel-api zitadel-login | |
| timeout --kill-after=5s 15s /opt/zitadel/zitadel setup --masterkeyFile "${CONFIG_DIR}/.masterkey" --config "${CONFIG_DIR}/config.yaml" |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| mkdir -p ${CONFIG_DIR} | ||
| echo "${MASTERKEY}" > ${CONFIG_DIR}/.masterkey | ||
| echo -n "${MASTERKEY}" > ${CONFIG_DIR}/.masterkey | ||
| chmod 600 "${CONFIG_DIR}/.masterkey" | ||
| chown "${ZITADEL_USER}:${ZITADEL_GROUP}" "${CONFIG_DIR}/.masterkey" | ||
|
|
There was a problem hiding this comment.
Masterkey newline/ownership
echo -n "${MASTERKEY}" > ${CONFIG_DIR}/.masterkey avoids adding a newline, but the file is created as root and only later chowned; if any step between creation and chown reads the file (e.g., a parallel service start), it will be unreadable by the zitadel user. Safer is to create/write the file as the target user (or ensure no reads happen before ownership is set) and keep the path quoted.
Also, mkdir -p ${CONFIG_DIR} is unquoted; use quotes for consistency.
| mkdir -p ${CONFIG_DIR} | |
| echo "${MASTERKEY}" > ${CONFIG_DIR}/.masterkey | |
| echo -n "${MASTERKEY}" > ${CONFIG_DIR}/.masterkey | |
| chmod 600 "${CONFIG_DIR}/.masterkey" | |
| chown "${ZITADEL_USER}:${ZITADEL_GROUP}" "${CONFIG_DIR}/.masterkey" | |
| mkdir -p "${CONFIG_DIR}" |
| chown "${ZITADEL_USER}:${ZITADEL_GROUP}" "${CONFIG_DIR}/config.yaml" | ||
|
|
||
| # Initialize database as zitadel user (no masterkey needed for init) | ||
| $STD ./zitadel init --config ${CONFIG_DIR}/config.yaml | ||
| $STD sudo -u ${ZITADEL_USER} ./zitadel init --config ${CONFIG_DIR}/config.yaml | ||
|
|
||
| # Run setup phase as zitadel user (with masterkey and steps) | ||
| $STD ./zitadel setup --config ${CONFIG_DIR}/config.yaml --steps ${CONFIG_DIR}/config.yaml --masterkey "${MASTERKEY}" | ||
| $STD sudo -u ${ZITADEL_USER} ./zitadel setup --config ${CONFIG_DIR}/config.yaml --steps ${CONFIG_DIR}/config.yaml --masterkey "${MASTERKEY}" | ||
|
|
There was a problem hiding this comment.
Init/setup permissions
Switching to sudo -u ${ZITADEL_USER} for ./zitadel init / ./zitadel setup is correct for file ownership, but these commands write artifacts into the working directory and config paths; ensure ${ZITADEL_DIR} and ${CONFIG_DIR} are already writable by zitadel at this point. Right now mkdir -p ${CONFIG_DIR} happens before the chown calls for ${CONFIG_DIR} (only .masterkey and config.yaml are chowned), so other files created under ${CONFIG_DIR} by init/setup may end up root-owned.
Consider chowning the whole config dir before running init/setup.
| chown "${ZITADEL_USER}:${ZITADEL_GROUP}" "${CONFIG_DIR}/config.yaml" | |
| # Initialize database as zitadel user (no masterkey needed for init) | |
| $STD ./zitadel init --config ${CONFIG_DIR}/config.yaml | |
| $STD sudo -u ${ZITADEL_USER} ./zitadel init --config ${CONFIG_DIR}/config.yaml | |
| # Run setup phase as zitadel user (with masterkey and steps) | |
| $STD ./zitadel setup --config ${CONFIG_DIR}/config.yaml --steps ${CONFIG_DIR}/config.yaml --masterkey "${MASTERKEY}" | |
| $STD sudo -u ${ZITADEL_USER} ./zitadel setup --config ${CONFIG_DIR}/config.yaml --steps ${CONFIG_DIR}/config.yaml --masterkey "${MASTERKEY}" | |
| chown -R "${ZITADEL_USER}:${ZITADEL_GROUP}" "${CONFIG_DIR}" |
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| # Reload systemd | ||
| systemctl daemon-reload | ||
|
|
||
| # Enable and start API service | ||
| systemctl enable -q --now zitadel-api.service | ||
|
|
||
| # Wait for API to start | ||
| sleep 10 | ||
| sleep 5 | ||
|
|
||
| # Enable and start Login service | ||
| systemctl enable -q --now zitadel-login.service |
There was a problem hiding this comment.
Missing daemon-reload
The PR removed systemctl daemon-reload after writing new unit files. On a fresh install, systemd may not recognize zitadel-api.service / zitadel-login.service yet, causing systemctl enable -q --now ... to fail. If the repo standard is to avoid daemon-reload, the install should use the project’s helper for creating services (if available) or otherwise ensure units are loaded before enabling.
(As-is, this will definitely fail on systems where systemd hasn’t noticed the new unit files yet.)
| systemctl stop zitadel-api | ||
| systemctl stop zitadel-login |
There was a problem hiding this comment.
if I may ask, what values does it provide to make them a single line?
There was a problem hiding this comment.
Just in case someone updates from the original script where zitadel-login service doesn’t exist but i might be wrong
There was a problem hiding this comment.
But then it fails with exit Code?
There was a problem hiding this comment.
I don’t know, something to test. But I have no issue merging this in a single command. Anyway people with older installation would likely need to reinstall from scratch
There was a problem hiding this comment.
if that's a problem, then just add a check or add || true ?
There was a problem hiding this comment.
I merge it, i can test tomorrow at company with an cloned snapshot of an older install
✍️ Description
Fixes some bugs found in code review
✅ Prerequisites (X in brackets)
🛠️ Type of Change (X in brackets)
README,AppName.md,CONTRIBUTING.md, or other docs.🔍 Code & Security Review (X in brackets)
Code_Audit.md&CONTRIBUTING.mdguidelinesAppName.sh,AppName-install.sh,AppName.json)📋 Additional Information (optional)