@@ -149,6 +149,21 @@ def set_attribute(self, key, value):
149
149
)
150
150
151
151
152
+ def _resolve_ignore_paths (
153
+ model_path : pathlib .Path , paths : Iterable [pathlib .Path ]
154
+ ) -> list [pathlib .Path ]:
155
+ model_root = model_path .resolve ()
156
+ cwd = pathlib .Path .cwd ()
157
+ resolved_paths = []
158
+ for p in paths :
159
+ candidate = (p if p .is_absolute () else (cwd / p )).resolve ()
160
+ try :
161
+ resolved_paths .append (candidate .relative_to (model_root ))
162
+ except ValueError :
163
+ continue
164
+ return resolved_paths
165
+
166
+
152
167
class _PKICmdGroup (click .Group ):
153
168
"""A custom group to configure the supported PKI methods."""
154
169
@@ -336,6 +351,9 @@ def _sign_sigstore(
336
351
)
337
352
span .set_attribute ("sigstore.use_staging" , use_staging )
338
353
try :
354
+ ignored = _resolve_ignore_paths (
355
+ model_path , list (ignore_paths ) + [signature ]
356
+ )
339
357
model_signing .signing .Config ().use_sigstore_signer (
340
358
use_ambient_credentials = use_ambient_credentials ,
341
359
use_staging = use_staging ,
@@ -346,8 +364,7 @@ def _sign_sigstore(
346
364
).set_hashing_config (
347
365
model_signing .hashing .Config ()
348
366
.set_ignored_paths (
349
- paths = list (ignore_paths ) + [signature ],
350
- ignore_git_paths = ignore_git_paths ,
367
+ paths = ignored , ignore_git_paths = ignore_git_paths
351
368
)
352
369
.set_allow_symlinks (allow_symlinks )
353
370
).sign (model_path , signature )
@@ -394,14 +411,14 @@ def _sign_private_key(
394
411
management protocols.
395
412
"""
396
413
try :
414
+ ignored = _resolve_ignore_paths (
415
+ model_path , list (ignore_paths ) + [signature ]
416
+ )
397
417
model_signing .signing .Config ().use_elliptic_key_signer (
398
418
private_key = private_key , password = password
399
419
).set_hashing_config (
400
420
model_signing .hashing .Config ()
401
- .set_ignored_paths (
402
- paths = list (ignore_paths ) + [signature ],
403
- ignore_git_paths = ignore_git_paths ,
404
- )
421
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
405
422
.set_allow_symlinks (allow_symlinks )
406
423
).sign (model_path , signature )
407
424
except Exception as err :
@@ -440,14 +457,14 @@ def _sign_pkcs11_key(
440
457
management protocols.
441
458
"""
442
459
try :
460
+ ignored = _resolve_ignore_paths (
461
+ model_path , list (ignore_paths ) + [signature ]
462
+ )
443
463
model_signing .signing .Config ().use_pkcs11_signer (
444
464
pkcs11_uri = pkcs11_uri
445
465
).set_hashing_config (
446
466
model_signing .hashing .Config ()
447
- .set_ignored_paths (
448
- paths = list (ignore_paths ) + [signature ],
449
- ignore_git_paths = ignore_git_paths ,
450
- )
467
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
451
468
.set_allow_symlinks (allow_symlinks )
452
469
).sign (model_path , signature )
453
470
except Exception as err :
@@ -493,16 +510,16 @@ def _sign_certificate(
493
510
Note that we don't offer certificate and key management protocols.
494
511
"""
495
512
try :
513
+ ignored = _resolve_ignore_paths (
514
+ model_path , list (ignore_paths ) + [signature ]
515
+ )
496
516
model_signing .signing .Config ().use_certificate_signer (
497
517
private_key = private_key ,
498
518
signing_certificate = signing_certificate ,
499
519
certificate_chain = certificate_chain ,
500
520
).set_hashing_config (
501
521
model_signing .hashing .Config ()
502
- .set_ignored_paths (
503
- paths = list (ignore_paths ) + [signature ],
504
- ignore_git_paths = ignore_git_paths ,
505
- )
522
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
506
523
.set_allow_symlinks (allow_symlinks )
507
524
).sign (model_path , signature )
508
525
except Exception as err :
@@ -549,16 +566,16 @@ def _sign_pkcs11_certificate(
549
566
Note that we don't offer certificate and key management protocols.
550
567
"""
551
568
try :
569
+ ignored = _resolve_ignore_paths (
570
+ model_path , list (ignore_paths ) + [signature ]
571
+ )
552
572
model_signing .signing .Config ().use_pkcs11_certificate_signer (
553
573
pkcs11_uri = pkcs11_uri ,
554
574
signing_certificate = signing_certificate ,
555
575
certificate_chain = certificate_chain ,
556
576
).set_hashing_config (
557
577
model_signing .hashing .Config ()
558
- .set_ignored_paths (
559
- paths = list (ignore_paths ) + [signature ],
560
- ignore_git_paths = ignore_git_paths ,
561
- )
578
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
562
579
.set_allow_symlinks (allow_symlinks )
563
580
).sign (model_path , signature )
564
581
except Exception as err :
@@ -636,15 +653,17 @@ def _verify_sigstore(
636
653
span .set_attribute ("sigstore.oidc_issuer" , identity_provider )
637
654
span .set_attribute ("sigstore.use_staging" , use_staging )
638
655
try :
656
+ ignored = _resolve_ignore_paths (
657
+ model_path , list (ignore_paths ) + [signature ]
658
+ )
639
659
model_signing .verifying .Config ().use_sigstore_verifier (
640
660
identity = identity ,
641
661
oidc_issuer = identity_provider ,
642
662
use_staging = use_staging ,
643
663
).set_hashing_config (
644
664
model_signing .hashing .Config ()
645
665
.set_ignored_paths (
646
- paths = list (ignore_paths ) + [signature ],
647
- ignore_git_paths = ignore_git_paths ,
666
+ paths = ignored , ignore_git_paths = ignore_git_paths
648
667
)
649
668
.set_allow_symlinks (allow_symlinks )
650
669
).set_ignore_unsigned_files (ignore_unsigned_files ).verify (
@@ -694,14 +713,14 @@ def _verify_private_key(
694
713
management protocols.
695
714
"""
696
715
try :
716
+ ignored = _resolve_ignore_paths (
717
+ model_path , list (ignore_paths ) + [signature ]
718
+ )
697
719
model_signing .verifying .Config ().use_elliptic_key_verifier (
698
720
public_key = public_key
699
721
).set_hashing_config (
700
722
model_signing .hashing .Config ()
701
- .set_ignored_paths (
702
- paths = list (ignore_paths ) + [signature ],
703
- ignore_git_paths = ignore_git_paths ,
704
- )
723
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
705
724
.set_allow_symlinks (allow_symlinks )
706
725
).set_ignore_unsigned_files (ignore_unsigned_files ).verify (
707
726
model_path , signature
@@ -756,15 +775,15 @@ def _verify_certificate(
756
775
logging .basicConfig (format = "%(message)s" , level = logging .INFO )
757
776
758
777
try :
778
+ ignored = _resolve_ignore_paths (
779
+ model_path , list (ignore_paths ) + [signature ]
780
+ )
759
781
model_signing .verifying .Config ().use_certificate_verifier (
760
782
certificate_chain = certificate_chain ,
761
783
log_fingerprints = log_fingerprints ,
762
784
).set_hashing_config (
763
785
model_signing .hashing .Config ()
764
- .set_ignored_paths (
765
- paths = list (ignore_paths ) + [signature ],
766
- ignore_git_paths = ignore_git_paths ,
767
- )
786
+ .set_ignored_paths (paths = ignored , ignore_git_paths = ignore_git_paths )
768
787
.set_allow_symlinks (allow_symlinks )
769
788
).set_ignore_unsigned_files (ignore_unsigned_files ).verify (
770
789
model_path , signature
0 commit comments