Pass overlay credentials via context in copy up.

Some VFS operations (those which operate on FDs) get their credentials via the
context instead of via an explicit creds param. For these cases, we must pass
the overlay credentials on the context.

PiperOrigin-RevId: 327881259
This commit is contained in:
Nicolas Lacasse
2020-08-21 15:06:09 -07:00
committed by gVisor bot
parent 5ec3d4ed3e
commit 5f33fdf37e
3 changed files with 26 additions and 21 deletions
+20
View File
@@ -34,3 +34,23 @@ func CredentialsFromContext(ctx context.Context) *Credentials {
}
return NewAnonymousCredentials()
}
// ContextWithCredentials returns a copy of ctx carrying creds.
func ContextWithCredentials(ctx context.Context, creds *Credentials) context.Context {
return &authContext{ctx, creds}
}
type authContext struct {
context.Context
creds *Credentials
}
// Value implements context.Context.
func (ac *authContext) Value(key interface{}) interface{} {
switch key {
case CtxCredentials:
return ac.creds
default:
return ac.Context.Value(key)
}
}