6
6
get_server_identity_JWT ,
7
7
validate_client_JWT_SVID ,
8
8
)
9
- from lib import spire_interactions
9
+ from lib import spire_interactions
10
10
from tools .docker_utils import get_build_env_image_digests
11
11
from pyspiffe .spiffe_id .spiffe_id import SpiffeId
12
+ from pyspiffe .workloadapi import default_jwt_source
12
13
13
14
from tools .config .config import parse_configuration
14
15
from tools .cli .cli import parse_arguments
25
26
options = parse_arguments ()
26
27
configuration = parse_configuration (options .config )
27
28
28
- if configuration ['spire-server' ].get ('spire-server-bin' ) :
29
- spire_interactions .spire_server_bin = configuration ['spire-server' ]['spire-server-bin' ]
29
+ if configuration ["spire-server" ].get ("spire-server-bin" ):
30
+ spire_interactions .spire_server_bin = configuration ["spire-server" ][
31
+ "spire-server-bin"
32
+ ]
30
33
31
- if configuration ['spire-server' ].get ('pre-command' ) :
32
- spire_interactions .pre_command = configuration ['spire-server' ]['pre-command' ]
33
- if configuration ['spire-server' ]['pre-command' ] == "\" \" " :
34
+ if configuration ["spire-agent" ].get ("spire-agent-socket" ):
35
+ spire_interactions .jwt_workload_api = default_jwt_source .DefaultJwtSource (
36
+ workload_api_client = None ,
37
+ spiffe_socket_path = f"unix://{ configuration ['spire-agent' ].get ('spire-agent-socket' )} " ,
38
+ timeout_in_seconds = None ,
39
+ )
40
+ else :
41
+ spire_interactions .jwt_workload_api = default_jwt_source .DefaultJwtSource (
42
+ workload_api_client = None ,
43
+ spiffe_socket_path = "unix:///tmp/spire-agent/public/api.sock" ,
44
+ timeout_in_seconds = None ,
45
+ )
46
+
47
+ if configuration ["spire-server" ].get ("pre-command" ):
48
+ spire_interactions .pre_command = configuration ["spire-server" ]["pre-command" ]
49
+ if configuration ["spire-server" ]["pre-command" ] == '""' :
34
50
spire_interactions .pre_command = ""
35
-
51
+
36
52
# Defining the trust domain (SPIRE Trust Domain)
37
- trust_domain = configuration [' spire-server' ][ ' trust-domain' ]
53
+ trust_domain = configuration [" spire-server" ][ " trust-domain" ]
38
54
39
55
# Perform vault login, to be able to run later operations against vault
40
- hvac_client = vault_login (configuration ['vault' ]['url' ], get_server_identity_JWT (), configuration ['vault' ]['server-role' ])
56
+ hvac_client = vault_login (
57
+ configuration ["vault" ]["url" ],
58
+ get_server_identity_JWT (),
59
+ configuration ["vault" ]["server-role" ],
60
+ )
41
61
42
62
43
63
# Dummy endpoint that handles the registration of compute nodes.
@@ -101,9 +121,7 @@ async def handle_client_registration():
101
121
102
122
# Create a spiffeID for the workloads on the client.
103
123
# Register workloads that have to run on this agent
104
- workload_spiffeID = SpiffeId (
105
- f"spiffe://{ trust_domain } /c/{ client_id } /workload"
106
- )
124
+ workload_spiffeID = SpiffeId (f"spiffe://{ trust_domain } /c/{ client_id } /workload" )
107
125
108
126
# Write the role bound to the workload's spiffeID
109
127
write_client_role (hvac_client , f"client_{ client_id } " , workload_spiffeID )
@@ -128,22 +146,34 @@ async def handle_client_registration():
128
146
"client_id" : client_id ,
129
147
"token" : agent_token ,
130
148
}
131
-
132
- # Spire-Agent binary
149
+
150
+ # Spire-Agent binary
133
151
result = entry_create (
134
- agent_spiffeID , workload_spiffeID , ["unix:sha256:5ebff0fdb3335ec0221c35dcc7d3a4433eb8a5073a15a6dcfdbbb95bb8dbfa8e" ]
152
+ agent_spiffeID ,
153
+ workload_spiffeID ,
154
+ [
155
+ "unix:sha256:5ebff0fdb3335ec0221c35dcc7d3a4433eb8a5073a15a6dcfdbbb95bb8dbfa8e"
156
+ ],
135
157
)
136
-
137
- # Python 3.9 binary
158
+
159
+ # Python 3.9 binary
138
160
result = entry_create (
139
- agent_spiffeID , workload_spiffeID , ["unix:sha256:956a50083eb7a58240fea28ac52ff39e9c04c5c74468895239b24bdf4760bffe" ]
161
+ agent_spiffeID ,
162
+ workload_spiffeID ,
163
+ [
164
+ "unix:sha256:956a50083eb7a58240fea28ac52ff39e9c04c5c74468895239b24bdf4760bffe"
165
+ ],
140
166
)
141
-
167
+
142
168
# Qemu x86_64 (For docker mac) // Could add Rosetta binary
143
169
result = entry_create (
144
- agent_spiffeID , workload_spiffeID , ["unix:sha256:3fc6c8fbd8fe429b67276854fbb5ae594118f7f0b10352a508477833b04ee9b7" ]
170
+ agent_spiffeID ,
171
+ workload_spiffeID ,
172
+ [
173
+ "unix:sha256:3fc6c8fbd8fe429b67276854fbb5ae594118f7f0b10352a508477833b04ee9b7"
174
+ ],
145
175
)
146
-
176
+
147
177
# Success
148
178
return {
149
179
"success" : True ,
@@ -176,9 +206,7 @@ async def handle_workload_creation():
176
206
client_id = hashlib .sha256 (client_id .encode ()).hexdigest ()[0 :9 ]
177
207
178
208
# Parse the spiffeID that will access the application
179
- spiffeID = SpiffeId (
180
- f"spiffe://{ trust_domain } /c/{ client_id } /s/{ data ['secret' ]} "
181
- )
209
+ spiffeID = SpiffeId (f"spiffe://{ trust_domain } /c/{ client_id } /s/{ data ['secret' ]} " )
182
210
183
211
# Check that the SVID correspond to the client_id (Can be removed if developper is certified)
184
212
if validate_client_JWT_SVID (data ["jwt" ], client_id ):
0 commit comments