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