-
Notifications
You must be signed in to change notification settings - Fork 81
Refactor SPIRE Integration and Optimize Spire Memory Footprint #1837
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
Open
gngram
wants to merge
7
commits into
tiiuae:main
Choose a base branch
from
gngram:pull/spire_module_update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffbed31
security(spiffe): add SPIRE server/agent modules and enable across VM…
everton-dematos 6fb22ed
remove cloud node and workload attestation from spire
gngram 96a231b
Enable spire patch and fix Agent ExecStart
everton-dematos e34b189
common config for spire
gngram 0ee16e4
stripped spire package to reduce memory foot print
gngram ece9c28
spire server and agent refactoring
gngram c824c63
update common configs for agents and server
gngram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| ./pwquality.nix | ||
| ./ssh-tarpit | ||
| ./fleet | ||
| ./spire | ||
| ./tpm2-packages.nix | ||
| ../../secureboot/secureboot.nix | ||
| ]; | ||
|
|
||
This file contains hidden or 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,162 @@ | ||
| # SPDX-FileCopyrightText: 2022-2026 TII (SSRC) and the Ghaf contributors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| cfg = config.ghaf.security.spire.agent; | ||
| dataDir = "/var/lib/spire/agent"; | ||
| runtimeDataDir = "/run/spire/agent"; | ||
| inherit (lib) | ||
| getExe | ||
| mkIf | ||
| mkOption | ||
| mkEnableOption | ||
| types | ||
| optionalString | ||
| ; | ||
| spire-package = config.ghaf.common.spire.package; | ||
|
|
||
| joinTokenConf = optionalString (cfg.nodeAttestationMode == "join_token") '' | ||
| join_token_file = "${cfg.settings.join_token.token}" | ||
| ''; | ||
| joinTokenPlugin = optionalString (cfg.nodeAttestationMode == "join_token") '' | ||
| NodeAttestor "join_token" { | ||
| plugin_data {} | ||
| } | ||
| ''; | ||
| agentConf = '' | ||
| agent { | ||
| data_dir = "${dataDir}" | ||
| log_level = "${cfg.logLevel}" | ||
| server_address = "${config.ghaf.common.spire.server.address}" | ||
| server_port = ${toString config.ghaf.common.spire.server.port} | ||
| trust_domain = "${config.ghaf.common.spire.server.trustDomain}" | ||
| trust_bundle_path = "${cfg.trustBundlePath}" | ||
| socket_path = "${runtimeDataDir}/agent.sock" | ||
| ${joinTokenConf} | ||
| } | ||
|
|
||
| plugins { | ||
| ${joinTokenPlugin} | ||
|
|
||
| WorkloadAttestor "unix" { | ||
| plugin_data {} | ||
| } | ||
| KeyManager "disk" { | ||
| plugin_data { | ||
| directory = "${dataDir}/keys" | ||
| } | ||
| } | ||
| } | ||
| ''; | ||
|
|
||
| server-health = pkgs.writeShellApplication { | ||
| name = "spire-server-healthcheck"; | ||
|
|
||
| runtimeInputs = [ | ||
| pkgs.curl | ||
| pkgs.spire-agent | ||
| ]; | ||
|
|
||
| text = '' | ||
| SERVER_URL="http://${config.ghaf.common.spire.server.address}:8080/ready" | ||
| MODE="${cfg.nodeAttestationMode}" | ||
|
|
||
| echo "Checking SPIRE Server readiness at $SERVER_URL..." | ||
|
|
||
| until curl --fail --silent "$SERVER_URL" > /dev/null 2>&1; do | ||
| echo "SPIRE Server is not ready yet. Retrying in 3 seconds..." | ||
| sleep 3 | ||
| done | ||
|
|
||
| if [ "$MODE" == "join_token" ]; then | ||
| while [ ! -e "${cfg.settings.join_token.token}" ]; do | ||
| echo "Waiting for server token..." | ||
| sleep 1 | ||
| done | ||
| fi | ||
| echo "SPIRE Server is ready! Starting SPIRE Agent..." | ||
| ''; | ||
| }; | ||
| in | ||
| { | ||
| _file = ./agent.nix; | ||
|
|
||
| options.ghaf.security.spire.agent = { | ||
| enable = mkEnableOption "SPIRE agent"; | ||
| nodeAttestationMode = mkOption { | ||
| type = types.spireNodeAttestationMode; | ||
| default = "join_token"; | ||
| description = "Node attestation mode"; | ||
| }; | ||
| workloads = mkOption { | ||
| type = types.spireWorkloads; | ||
| default = [ ]; | ||
| description = "List of workloads for this spire agent"; | ||
| }; | ||
| trustBundlePath = mkOption { | ||
| type = types.str; | ||
| default = "/etc/common/spire/bundle.pem"; | ||
| description = "Path to the SPIRE trust bundle PEM file (used to verify the server during bootstrap)"; | ||
| }; | ||
| logLevel = mkOption { | ||
| type = types.str; | ||
| default = "INFO"; | ||
| description = "SPIRE server log level"; | ||
| }; | ||
| settings = { | ||
| join_token = { | ||
| token = mkOption { | ||
| type = types.path; | ||
| default = "/etc/common/spire/tokens/${config.networking.hostName}.token"; | ||
| description = "SPIRE server log level"; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| environment.etc."spire/agent.conf".text = agentConf; | ||
| services.spire.agent = { | ||
| enable = true; | ||
| package = spire-package; | ||
| configFile = "/etc/spire/agent.conf"; | ||
| }; | ||
|
|
||
gngram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| environment.systemPackages = [ spire-package ]; | ||
| systemd = { | ||
| services = { | ||
| spire-agent = { | ||
| requires = [ "network-online.target" ]; | ||
| after = [ | ||
| "network-online.target" | ||
| ]; | ||
|
|
||
| unitConfig = { | ||
| RequiresMountsFor = [ "/etc/common" ]; | ||
| }; | ||
|
|
||
| serviceConfig = { | ||
| ExecStartPre = getExe server-health; | ||
| NoNewPrivileges = true; | ||
| PrivateTmp = true; | ||
| ProtectSystem = "strict"; | ||
| ProtectHome = true; | ||
| ReadWritePaths = [ | ||
| "${dataDir}" | ||
| "${runtimeDataDir}" | ||
| ]; | ||
| }; | ||
| }; | ||
| }; | ||
| tmpfiles.rules = [ | ||
| "d /run/spire 2750 spire-agent spire-agent - -" | ||
| "d ${runtimeDataDir} 2750 spire-agent spire-agent - -" | ||
| ]; | ||
| }; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.