115
115
help = "Path to the signing certificate, as a PEM-encoded file." ,
116
116
)
117
117
118
+ # Decorator for the commonly used option to allow symlinks
119
+ _allow_symlinks_option = click .option (
120
+ "--allow_symlinks" ,
121
+ type = bool ,
122
+ is_flag = True ,
123
+ help = "Whether to allow following symlinks when signing or verifying files." ,
124
+ )
125
+
118
126
119
127
class _PKICmdGroup (click .Group ):
120
128
"""A custom group to configure the supported PKI methods."""
@@ -194,6 +202,7 @@ def _sign() -> None:
194
202
@_model_path_argument
195
203
@_ignore_paths_option
196
204
@_ignore_git_paths_option
205
+ @_allow_symlinks_option
197
206
@_write_signature_option
198
207
@_sigstore_staging_option
199
208
@click .option (
@@ -236,6 +245,7 @@ def _sign_sigstore(
236
245
model_path : pathlib .Path ,
237
246
ignore_paths : Iterable [pathlib .Path ],
238
247
ignore_git_paths : bool ,
248
+ allow_symlinks : bool ,
239
249
signature : pathlib .Path ,
240
250
use_ambient_credentials : bool ,
241
251
use_staging : bool ,
@@ -269,10 +279,12 @@ def _sign_sigstore(
269
279
client_id = client_id ,
270
280
client_secret = client_secret ,
271
281
).set_hashing_config (
272
- model_signing .hashing .Config ().set_ignored_paths (
282
+ model_signing .hashing .Config ()
283
+ .set_ignored_paths (
273
284
paths = list (ignore_paths ) + [signature ],
274
285
ignore_git_paths = ignore_git_paths ,
275
286
)
287
+ .set_allow_symlinks (allow_symlinks )
276
288
).sign (model_path , signature )
277
289
except Exception as err :
278
290
click .echo (f"Signing failed with error: { err } " , err = True )
@@ -285,6 +297,7 @@ def _sign_sigstore(
285
297
@_model_path_argument
286
298
@_ignore_paths_option
287
299
@_ignore_git_paths_option
300
+ @_allow_symlinks_option
288
301
@_write_signature_option
289
302
@_private_key_option
290
303
@click .option (
@@ -297,6 +310,7 @@ def _sign_private_key(
297
310
model_path : pathlib .Path ,
298
311
ignore_paths : Iterable [pathlib .Path ],
299
312
ignore_git_paths : bool ,
313
+ allow_symlinks : bool ,
300
314
signature : pathlib .Path ,
301
315
private_key : pathlib .Path ,
302
316
password : Optional [str ] = None ,
@@ -318,10 +332,12 @@ def _sign_private_key(
318
332
model_signing .signing .Config ().use_elliptic_key_signer (
319
333
private_key = private_key , password = password
320
334
).set_hashing_config (
321
- model_signing .hashing .Config ().set_ignored_paths (
335
+ model_signing .hashing .Config ()
336
+ .set_ignored_paths (
322
337
paths = list (ignore_paths ) + [signature ],
323
338
ignore_git_paths = ignore_git_paths ,
324
339
)
340
+ .set_allow_symlinks (allow_symlinks )
325
341
).sign (model_path , signature )
326
342
except Exception as err :
327
343
click .echo (f"Signing failed with error: { err } " , err = True )
@@ -334,12 +350,14 @@ def _sign_private_key(
334
350
@_model_path_argument
335
351
@_ignore_paths_option
336
352
@_ignore_git_paths_option
353
+ @_allow_symlinks_option
337
354
@_write_signature_option
338
355
@_pkcs11_uri_option
339
356
def _sign_pkcs11_key (
340
357
model_path : pathlib .Path ,
341
358
ignore_paths : Iterable [pathlib .Path ],
342
359
ignore_git_paths : bool ,
360
+ allow_symlinks : bool ,
343
361
signature : pathlib .Path ,
344
362
pkcs11_uri : str ,
345
363
) -> None :
@@ -360,10 +378,12 @@ def _sign_pkcs11_key(
360
378
model_signing .signing .Config ().use_pkcs11_signer (
361
379
pkcs11_uri = pkcs11_uri
362
380
).set_hashing_config (
363
- model_signing .hashing .Config ().set_ignored_paths (
381
+ model_signing .hashing .Config ()
382
+ .set_ignored_paths (
364
383
paths = list (ignore_paths ) + [signature ],
365
384
ignore_git_paths = ignore_git_paths ,
366
385
)
386
+ .set_allow_symlinks (allow_symlinks )
367
387
).sign (model_path , signature )
368
388
except Exception as err :
369
389
click .echo (f"Signing failed with error: { err } " , err = True )
@@ -376,6 +396,7 @@ def _sign_pkcs11_key(
376
396
@_model_path_argument
377
397
@_ignore_paths_option
378
398
@_ignore_git_paths_option
399
+ @_allow_symlinks_option
379
400
@_write_signature_option
380
401
@_private_key_option
381
402
@_signing_certificate_option
@@ -384,6 +405,7 @@ def _sign_certificate(
384
405
model_path : pathlib .Path ,
385
406
ignore_paths : Iterable [pathlib .Path ],
386
407
ignore_git_paths : bool ,
408
+ allow_symlinks : bool ,
387
409
signature : pathlib .Path ,
388
410
private_key : pathlib .Path ,
389
411
signing_certificate : pathlib .Path ,
@@ -411,10 +433,12 @@ def _sign_certificate(
411
433
signing_certificate = signing_certificate ,
412
434
certificate_chain = certificate_chain ,
413
435
).set_hashing_config (
414
- model_signing .hashing .Config ().set_ignored_paths (
436
+ model_signing .hashing .Config ()
437
+ .set_ignored_paths (
415
438
paths = list (ignore_paths ) + [signature ],
416
439
ignore_git_paths = ignore_git_paths ,
417
440
)
441
+ .set_allow_symlinks (allow_symlinks )
418
442
).sign (model_path , signature )
419
443
except Exception as err :
420
444
click .echo (f"Signing failed with error: { err } " , err = True )
@@ -427,6 +451,7 @@ def _sign_certificate(
427
451
@_model_path_argument
428
452
@_ignore_paths_option
429
453
@_ignore_git_paths_option
454
+ @_allow_symlinks_option
430
455
@_write_signature_option
431
456
@_pkcs11_uri_option
432
457
@_signing_certificate_option
@@ -435,6 +460,7 @@ def _sign_pkcs11_certificate(
435
460
model_path : pathlib .Path ,
436
461
ignore_paths : Iterable [pathlib .Path ],
437
462
ignore_git_paths : bool ,
463
+ allow_symlinks : bool ,
438
464
signature : pathlib .Path ,
439
465
pkcs11_uri : str ,
440
466
signing_certificate : pathlib .Path ,
@@ -463,10 +489,12 @@ def _sign_pkcs11_certificate(
463
489
signing_certificate = signing_certificate ,
464
490
certificate_chain = certificate_chain ,
465
491
).set_hashing_config (
466
- model_signing .hashing .Config ().set_ignored_paths (
492
+ model_signing .hashing .Config ()
493
+ .set_ignored_paths (
467
494
paths = list (ignore_paths ) + [signature ],
468
495
ignore_git_paths = ignore_git_paths ,
469
496
)
497
+ .set_allow_symlinks (allow_symlinks )
470
498
).sign (model_path , signature )
471
499
except Exception as err :
472
500
click .echo (f"Signing failed with error: { err } " , err = True )
@@ -497,6 +525,7 @@ def _verify() -> None:
497
525
@_read_signature_option
498
526
@_ignore_paths_option
499
527
@_ignore_git_paths_option
528
+ @_allow_symlinks_option
500
529
@_sigstore_staging_option
501
530
@click .option (
502
531
"--identity" ,
@@ -517,6 +546,7 @@ def _verify_sigstore(
517
546
signature : pathlib .Path ,
518
547
ignore_paths : Iterable [pathlib .Path ],
519
548
ignore_git_paths : bool ,
549
+ allow_symlinks : bool ,
520
550
identity : str ,
521
551
identity_provider : str ,
522
552
use_staging : bool ,
@@ -537,10 +567,12 @@ def _verify_sigstore(
537
567
oidc_issuer = identity_provider ,
538
568
use_staging = use_staging ,
539
569
).set_hashing_config (
540
- model_signing .hashing .Config ().set_ignored_paths (
570
+ model_signing .hashing .Config ()
571
+ .set_ignored_paths (
541
572
paths = list (ignore_paths ) + [signature ],
542
573
ignore_git_paths = ignore_git_paths ,
543
574
)
575
+ .set_allow_symlinks (allow_symlinks )
544
576
).verify (model_path , signature )
545
577
except Exception as err :
546
578
click .echo (f"Verification failed with error: { err } " , err = True )
@@ -554,6 +586,7 @@ def _verify_sigstore(
554
586
@_read_signature_option
555
587
@_ignore_paths_option
556
588
@_ignore_git_paths_option
589
+ @_allow_symlinks_option
557
590
@click .option (
558
591
"--public_key" ,
559
592
type = pathlib .Path ,
@@ -566,6 +599,7 @@ def _verify_private_key(
566
599
signature : pathlib .Path ,
567
600
ignore_paths : Iterable [pathlib .Path ],
568
601
ignore_git_paths : bool ,
602
+ allow_symlinks : bool ,
569
603
public_key : pathlib .Path ,
570
604
) -> None :
571
605
"""Verity using a public key (paired with a private one).
@@ -585,10 +619,12 @@ def _verify_private_key(
585
619
model_signing .verifying .Config ().use_elliptic_key_verifier (
586
620
public_key = public_key
587
621
).set_hashing_config (
588
- model_signing .hashing .Config ().set_ignored_paths (
622
+ model_signing .hashing .Config ()
623
+ .set_ignored_paths (
589
624
paths = list (ignore_paths ) + [signature ],
590
625
ignore_git_paths = ignore_git_paths ,
591
626
)
627
+ .set_allow_symlinks (allow_symlinks )
592
628
).verify (model_path , signature )
593
629
except Exception as err :
594
630
click .echo (f"Verification failed with error: { err } " , err = True )
@@ -602,6 +638,7 @@ def _verify_private_key(
602
638
@_read_signature_option
603
639
@_ignore_paths_option
604
640
@_ignore_git_paths_option
641
+ @_allow_symlinks_option
605
642
@_certificate_root_of_trust_option
606
643
@click .option (
607
644
"--log_fingerprints" ,
@@ -616,6 +653,7 @@ def _verify_certificate(
616
653
signature : pathlib .Path ,
617
654
ignore_paths : Iterable [pathlib .Path ],
618
655
ignore_git_paths : bool ,
656
+ allow_symlinks : bool ,
619
657
certificate_chain : Iterable [pathlib .Path ],
620
658
log_fingerprints : bool ,
621
659
) -> None :
@@ -640,10 +678,12 @@ def _verify_certificate(
640
678
certificate_chain = certificate_chain ,
641
679
log_fingerprints = log_fingerprints ,
642
680
).set_hashing_config (
643
- model_signing .hashing .Config ().set_ignored_paths (
681
+ model_signing .hashing .Config ()
682
+ .set_ignored_paths (
644
683
paths = list (ignore_paths ) + [signature ],
645
684
ignore_git_paths = ignore_git_paths ,
646
685
)
686
+ .set_allow_symlinks (allow_symlinks )
647
687
).verify (model_path , signature )
648
688
except Exception as err :
649
689
click .echo (f"Verification failed with error: { err } " , err = True )
0 commit comments