Created
April 19, 2019 07:08
-
-
Save kunalkushwaha/775b063671a62f968ff111d266764d04 to your computer and use it in GitHub Desktop.
Example to used buildkit entitlements with LLB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/moby/buildkit/client" | |
"github.com/moby/buildkit/client/llb" | |
"github.com/moby/buildkit/util/entitlements" | |
) | |
func main() { | |
c, err := client.New(context.TODO(), "unix:///run/buildkit/buildkitd.sock") | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
r, err := c.ListWorkers(context.TODO()) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(r) | |
st := llb.Image("busybox:latest"). | |
Run(llb.Shlex(`sh -c 'cat /proc/self/status | grep CapEff | grep "00000000a80425fb"'`)) | |
def, err := st.Marshal() | |
if err != nil { | |
panic(err) | |
} | |
allowedEntitlements := []entitlements.Entitlement{} | |
_, err = c.Solve(context.TODO(), def, client.SolveOpt{ | |
AllowedEntitlements: allowedEntitlements, | |
}, nil) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("confined profile works fine...") | |
st2 := llb.Image("busybox:latest"). | |
Run(llb.Shlex(`sh -c 'cat /proc/self/status | grep CapEff | grep "0000003fffffffff"'`), llb.Security(llb.SecurityModeInsecure)) | |
def, err = st2.Marshal() | |
if err != nil { | |
panic(err) | |
} | |
allowedEntitlements = []entitlements.Entitlement{entitlements.EntitlementSecurityInsecure} | |
_, err = c.Solve(context.Background(), def, client.SolveOpt{ | |
AllowedEntitlements: allowedEntitlements, | |
}, nil) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("unconfined profile works fine...") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test above example.
run buildkit daemon with
--allow-insecure-entitlement security.insecure
run test program