@@ -2787,7 +2787,7 @@ func testSourceDateEpochClamp(t *testing.T, sb integration.Sandbox) {
27872787
27882788 var bboxConfig []byte
27892789 _ , err = c .Build (sb .Context (), SolveOpt {}, "" , func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
2790- _ , bboxConfig , err = c .ResolveImageConfig (ctx , "docker.io/library/busybox:latest" , llb.ResolveImageConfigOpt {})
2790+ _ , _ , bboxConfig , err = c .ResolveImageConfig (ctx , "docker.io/library/busybox:latest" , llb.ResolveImageConfigOpt {})
27912791 if err != nil {
27922792 return nil , err
27932793 }
@@ -9470,32 +9470,88 @@ func testSourcePolicy(t *testing.T, sb integration.Sandbox) {
94709470 }
94719471
94729472 t .Run ("Frontend policies" , func (t * testing.T ) {
9473- denied := "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md"
9474- frontend := func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
9475- st := llb .Image ("busybox:1.34.1-uclibc" ).File (
9476- llb .Copy (llb .HTTP (denied ),
9477- "README.md" , "README.md" ))
9478- def , err := st .Marshal (sb .Context ())
9479- if err != nil {
9480- return nil , err
9473+ t .Run ("deny http" , func (t * testing.T ) {
9474+ denied := "https://raw.githubusercontent.com/moby/buildkit/v0.10.1/README.md"
9475+ frontend := func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
9476+ st := llb .Image ("busybox:1.34.1-uclibc" ).File (
9477+ llb .Copy (llb .HTTP (denied ),
9478+ "README.md" , "README.md" ))
9479+ def , err := st .Marshal (sb .Context ())
9480+ if err != nil {
9481+ return nil , err
9482+ }
9483+ return c .Solve (ctx , gateway.SolveRequest {
9484+ Definition : def .ToPB (),
9485+ SourcePolicies : []* sourcepolicypb.Policy {{
9486+ Rules : []* sourcepolicypb.Rule {
9487+ {
9488+ Action : sourcepolicypb .PolicyAction_DENY ,
9489+ Selector : & sourcepolicypb.Selector {
9490+ Identifier : denied ,
9491+ },
9492+ },
9493+ },
9494+ }},
9495+ })
94819496 }
9482- return c .Solve (ctx , gateway.SolveRequest {
9483- Definition : def .ToPB (),
9484- SourcePolicies : []* sourcepolicypb.Policy {{
9485- Rules : []* sourcepolicypb.Rule {
9486- {
9487- Action : sourcepolicypb .PolicyAction_DENY ,
9488- Selector : & sourcepolicypb.Selector {
9489- Identifier : denied ,
9497+
9498+ _ , err = c .Build (sb .Context (), SolveOpt {}, "" , frontend , nil )
9499+ require .ErrorContains (t , err , sourcepolicy .ErrSourceDenied .Error ())
9500+ })
9501+ t .Run ("resolve image config" , func (t * testing.T ) {
9502+ frontend := func (ctx context.Context , c gateway.Client ) (* gateway.Result , error ) {
9503+ const (
9504+ origRef = "docker.io/library/busybox:1.34.1-uclibc"
9505+ updatedRef = "docker.io/library/busybox:latest"
9506+ )
9507+ pol := []* sourcepolicypb.Policy {
9508+ {
9509+ Rules : []* sourcepolicypb.Rule {
9510+ {
9511+ Action : sourcepolicypb .PolicyAction_DENY ,
9512+ Selector : & sourcepolicypb.Selector {
9513+ Identifier : "*" ,
9514+ },
9515+ },
9516+ {
9517+ Action : sourcepolicypb .PolicyAction_ALLOW ,
9518+ Selector : & sourcepolicypb.Selector {
9519+ Identifier : "docker-image://" + updatedRef + "*" ,
9520+ },
9521+ },
9522+ {
9523+ Action : sourcepolicypb .PolicyAction_CONVERT ,
9524+ Selector : & sourcepolicypb.Selector {
9525+ Identifier : "docker-image://" + origRef ,
9526+ },
9527+ Updates : & sourcepolicypb.Update {
9528+ Identifier : "docker-image://" + updatedRef ,
9529+ },
94909530 },
94919531 },
94929532 },
9493- }},
9494- })
9495- }
9533+ }
94969534
9497- _ , err = c .Build (sb .Context (), SolveOpt {}, "" , frontend , nil )
9498- require .ErrorContains (t , err , sourcepolicy .ErrSourceDenied .Error ())
9535+ ref , dgst , _ , err := c .ResolveImageConfig (ctx , origRef , llb.ResolveImageConfigOpt {
9536+ SourcePolicies : pol ,
9537+ })
9538+ if err != nil {
9539+ return nil , err
9540+ }
9541+ require .Equal (t , updatedRef , ref )
9542+ st := llb .Image (ref + "@" + dgst .String ())
9543+ def , err := st .Marshal (sb .Context ())
9544+ if err != nil {
9545+ return nil , err
9546+ }
9547+ return c .Solve (ctx , gateway.SolveRequest {
9548+ Definition : def .ToPB (),
9549+ SourcePolicies : pol ,
9550+ })
9551+ }
9552+ _ , err = c .Build (sb .Context (), SolveOpt {}, "" , frontend , nil )
9553+ require .NoError (t , err )
9554+ })
94999555 })
95009556}
95019557
0 commit comments