Deploy Aikido Safe Chain per-user on macOS devices managed by Iru (Kandji), even though Kandji scripts run at the machine/root level.
kandji-safe-chain-detect.shkandji-safe-chain-remediate.shREADME.md(implementation and usage guide)
- Reviewed prior script style in
sample/to match operational patterns:- root-level execution
- explicit logging
- clear exit code behavior for detect/remediate flow
- Designed user enumeration for local profiles:
- enumerate local users from
dscl - include only real local user accounts (
uid >= 500, valid home directory, non-login-disabled shell)
- enumerate local users from
- Added compliance checks per profile:
~/.safe-chain/bin/safe-chainexists and is executable- version policy via
SAFE_CHAIN_VERSION_POLICY/SAFE_CHAIN_MINIMUM_VERSION(see README) - shell profile files contain Safe Chain integration markers
- Implemented version awareness:
latest: either query GitHub releases API fortag_name, or useSAFE_CHAIN_RELEASE_TAGto pin the expected tag (no API); default pin1.4.6, override withexport SAFE_CHAIN_RELEASE_TAG=""to track GitHub latestminimum: compare installed version toSAFE_CHAIN_MINIMUM_VERSIONonly (no API in detect); validate normalized minimum withis_valid_version_compare_token; remediate usesSAFE_CHAIN_RELEASE_TAGif set, else fetches latest when an install is required- dotted semver-style comparison (e.g.
1.2.2vs1.4.6) usingsort -Vafter normalization
- Implemented per-user remediation:
- run installer as each user context with explicit
HOMEand user-first PATH - prefer
launchctl asuser ... sudo -u ...and fallback tosudo -uif needed - use a release-tagged installer URL (
releases/download/<tag>/install-safe-chain.sh); optionalSAFE_CHAIN_INSTALLER_SHA256(requires pin): download,sha256sum -corshasum -a 256 -c, thensh - include a fallback direct binary install if installer fails due to local nvm/npm/volta cleanup edge cases
- re-verify version + shell markers after install (rules depend on
latestvsminimum)
- run installer as each user context with explicit
- Added logs in
/var/log/safe-chain-kandji/for troubleshooting.
- Detect returns:
0when all eligible users are compliant (or no eligible users are found)1when one or more users require remediation, or whenlatestmode cannot determine the latest version (or policy variables are invalid)
- Remediate returns:
0when all required remediations succeed1when any user remediation fails, or when a release tag cannot be resolved for an install that is needed (or policy variables are invalid)
- Aikido Safe Chain is upstream software by AikidoSec (AikidoSec/safe-chain); this repo only ships Kandji automation around it.
- Installer URL pattern:
https://github.com/AikidoSec/safe-chain/releases/download/<tag>/install-safe-chain.sh(pipe tosh, or checksum path whenSAFE_CHAIN_INSTALLER_SHA256is set). - Verification parses
safe-chain --versionfirst, thensafe-chain -v, matching output of the formCurrent safe-chain version: <version>. - Shell integration is validated by checking user shell startup files (bash/zsh profiles plus Fish
config.fishandconf.d/*.fish) for Safe Chain markers.