Skip to content

Commit b672e82

Browse files
committed
adapting job preparation to config file usage
1 parent a905eb0 commit b672e82

File tree

8 files changed

+34
-14
lines changed

8 files changed

+34
-14
lines changed

client/container_preparation/input_logic/run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ PATH="$PATH:/sd-container/tools/input_logic/"
77
echo "[SD-Container][Input-Logic] : Getting data decryption key from vault"
88

99
# Get token via vault login. The data_login environment variable need to be exported from calling script
10-
data_token=$(curl -s --request POST --data "$data_login" http://${vault}/v1/auth/jwt/login | jq '.auth.client_token' -r) || exit 1
10+
data_token=$(curl -s --request POST --data "$data_login" $vault/v1/auth/jwt/login | jq '.auth.client_token' -r) || exit 1
1111

1212
# Use the token to access the key. The data_path environment variable needs to be exported from calling script
13-
data_key=$(curl -s -H "X-Vault-Token: $data_token" http://${vault}/v1/kv/data/${data_path} | jq '.data.data.key' -r) || exit 1
13+
data_key=$(curl -s -H "X-Vault-Token: $data_token" $vault/v1/kv/data/${data_path} | jq '.data.data.key' -r) || exit 1
1414

1515
# Write the key in an encrypted volume
1616
echo "$data_key" > /sd-container/encrypted/decryption_key

client/job_preparation/lib/sbatch_generation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def boostrap_from_template(options: argparse.Namespace, template_path: str) -> s
4444
sbatch = sbatch.replace("ACCOUNT", options.account)
4545
sbatch = sbatch.replace("NODELIST", options.nodelist)
4646
sbatch = sbatch.replace("WORKDIR", options.workdir)
47-
sbatch = sbatch.replace("TRUST_DOMAIN", "lumi-sd-dev")
47+
sbatch = sbatch.replace("TRUST_DOMAIN", options.trust_domain)
48+
sbatch = sbatch.replace("VAULT_ADDRESS", options.vault_address)
4849

4950
# Dataset info
5051
sbatch = sbatch.replace("DATA_PATH", options.data_path_at_rest)

client/job_preparation/prepare_job.py

+11
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
sys.path.append(os.path.expanduser("../../../")) # For cli usage
77
sys.path.append(os.path.expanduser("../../")) # For inside-container usage
88
from utils.ssh_utils import ssh_connect, ssh_copy_file, ssh_run_command
9+
from utils.conf.client.conf import parse_configuration
910
from time import sleep
1011
from pyrage import x25519
1112

1213
if __name__ == "__main__":
1314
# Parse arguments
1415
options = check_arguments(parse_arguments())
1516

17+
# Parse configuration
18+
configuration = parse_configuration(options.config)
19+
20+
# Parse configuration as options
21+
options.trust_domain = configuration['spire-server']['trust-domain']
22+
options.vault_address = configuration['vault']['url']
23+
1624
# Connect via SSH to supercomputer
1725
ssh_client = ssh_connect(options.username)
1826

@@ -39,6 +47,9 @@
3947

4048
# Copy SBATCH to supercomputer
4149
ssh_copy_file(ssh_client, sbatch_path, f"~/")
50+
51+
# Copy config file to supercomputer
52+
ssh_copy_file(ssh_client, options.config, f"~/.config/hpcs.conf")
4253

4354
# Create public encryption key for output data
4455
ident = x25519.Identity.generate()

client/job_preparation/utils/cli/cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def parse_arguments() -> argparse.Namespace:
1111
parser = argparse.ArgumentParser(description="CLI Optinons")
1212

1313
parser.add_argument(
14-
"--username",
15-
"-u",
16-
required=True,
14+
"--config",
1715
type=str,
18-
help="username on supercomputer",
16+
required=True,
17+
default="/tmp/hpcs-client.conf",
18+
help="Configuration file (INI Format) (default: /tmp/hpcs-client.conf)",
1919
)
2020
parser.add_argument(
2121
"--job-name",

client/job_preparation/utils/sbatch.template

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ mkdir -p ${WORKING_DIRECTORY}
6161
echo -e "${YELLOW}[LUMI-SD]${NC}${BLUE}[Job]${NC} Running agent registration"
6262

6363
# Spawn spire-agent
64-
cd ~/LUMI-secure-processing || exit 1
65-
python3 ./utils/spawn_agent.py -cn > $WORKING_DIRECTORY/agent.log 2> $WORKING_DIRECTORY/agent.log &
64+
cd ~/HPCS || exit 1
65+
python3 ./utils/spawn_agent.py --config ~/.config/hpcs-client.conf -cn > $WORKING_DIRECTORY/agent.log 2> $WORKING_DIRECTORY/agent.log &
6666
spire_agent_pid=$!
6767

6868
# Wait until agent runs properly
@@ -85,18 +85,18 @@ echo "Logging in to the vault ..."
8585

8686
# Log in to the vault using SVID, access role
8787
echo "{\"role\": \"APPLICATION_ACCESS_ROLE\", \"jwt\" : \"$svid\"}" > /tmp/login
88-
application_token=$(curl -s --request POST --data @/tmp/login http://${vault}/v1/auth/jwt/login | jq '.auth.client_token' -r) || cleanup $spire_agent_pid 1
88+
application_token=$(curl -s --request POST --data @/tmp/login $vault/v1/auth/jwt/login | jq '.auth.client_token' -r) || cleanup $spire_agent_pid 1
8989

9090
echo "Getting container decryption key ..."
9191

9292
# Use provided vault token (from login) to access secrets
93-
data_key=$(curl -s -H "X-Vault-Token: $application_token" http://${vault}/v1/kv/data/APPLICATION_SECRET_PATH | jq '.data.data.key' -r) || cleanup $spire_agent_pid 1
93+
data_key=$(curl -s -H "X-Vault-Token: $application_token" $vault/v1/kv/data/APPLICATION_SECRET_PATH | jq '.data.data.key' -r) || cleanup $spire_agent_pid 1
9494
echo "$data_key" > /tmp/container_key
9595

9696
echo "Decrypting container image ..."
9797

9898
# Decrypt the container image
99-
~/LUMI-secure-processing/client/container_preparation/input_logic/age --decrypt -i /tmp/container_key -o $WORKING_DIRECTORY/app.sif APPLICATION_PATH || exit 1
99+
~/HPCS/client/container_preparation/input_logic/age --decrypt -i /tmp/container_key -o $WORKING_DIRECTORY/app.sif APPLICATION_PATH || exit 1
100100

101101
echo -e "${YELLOW}[LUMI-SD]${NC}${BLUE}[Job]${NC} Creating encrypted volumes"
102102

utils/conf/client/conf.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ def parse_configuration(path : str):
55
config = ConfigParser()
66
config.read(path)
77

8+
if not 'supercomputer' in config:
9+
raise NoSectionError("supercomputer section missing in configuration file, aborting")
10+
811
if not 'spire-server' in config:
912
raise NoSectionError("hpcs-server section missing in configuration file, aborting")
1013

@@ -14,6 +17,9 @@ def parse_configuration(path : str):
1417
if not 'vault' in config:
1518
raise NoSectionError("vault section missing in configuration file, aborting")
1619

20+
if not 'address' in config['supercomputer'] or not 'username' in config['supercomputer']:
21+
raise NoOptionError("'spire-server' section is incomplete in configuration file, aborting")
22+
1723
if not 'address' in config['spire-server'] or not 'port' in config['spire-server'] or not 'trust-domain' in config['spire-server']:
1824
raise NoOptionError("'spire-server' section is incomplete in configuration file, aborting")
1925

utils/ship_a_key.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def parse_arguments() -> argparse.ArgumentParser:
3030
parser.add_argument(
3131
"--config",
3232
required=True,
33-
help="Path to the client configuration file",
33+
default="/tmp/hpcs-client.conf",
34+
help="Configuration file (INI Format) (default: /tmp/hpcs-client.conf)",
3435
)
3536
parser.add_argument(
3637
"--users",

utils/spawn_agent.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def parse_arguments():
1414
parser.add_argument(
1515
"--config",
1616
required=True,
17-
help="Path to the client configuration file",
17+
default="/tmp/hpcs-client.conf",
18+
help="Configuration file (INI Format) (default: /tmp/hpcs-client.conf)",
1819
)
1920
parser.add_argument(
2021
"--socketpath",

0 commit comments

Comments
 (0)