-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store auth in keyring and transfer it to nydusd via environment variable #512
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #512 +/- ##
==========================================
+ Coverage 37.83% 38.37% +0.53%
==========================================
Files 60 62 +2
Lines 7092 7339 +247
==========================================
+ Hits 2683 2816 +133
- Misses 4097 4188 +91
- Partials 312 335 +23
|
af671f5
to
d03befe
Compare
pkg/manager/daemon_adaptor.go
Outdated
@@ -192,6 +195,19 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool) | |||
|
|||
cmd := exec.Command(nydusdPath, args...) | |||
|
|||
if config.IsKeyringEnabled() && !config.IsFusedevSharedModeEnabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Daemon has its own working mode which means nydusd daemons can work in the different modes in a single node.
Better to judge by daemon, we already have some helper functions doing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/filesystem/fs.go
Outdated
err = daemonconfig.SupplementDaemonConfig(cfg, imageID, snapshotID, false, labels, params) | ||
var updateErr error | ||
err = daemonconfig.SupplementDaemonConfig(cfg, imageID, snapshotID, false, labels, params, func(imageHost string, keyChain *auth.PassKeyChain) { | ||
logrus.Infof("add key for %s", imageHost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to lower the log level to Debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/manager/daemon_adaptor.go
Outdated
@@ -192,6 +195,19 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool) | |||
|
|||
cmd := exec.Command(nydusdPath, args...) | |||
|
|||
if config.IsKeyringEnabled() && !config.IsFusedevSharedModeEnabled() { | |||
c, err := daemonconfig.NewDaemonConfig(d.States.FsDriver, configPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid the current way to identify a container image reference's host is not agile. For the dedicated mode nydusd daemon, it only has a rafs instance in its Instances where we can calculate what host is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/keyring/keyring.go
Outdated
@@ -0,0 +1,42 @@ | |||
package keyring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add license claim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/daemon/daemon.go
Outdated
@@ -66,6 +71,7 @@ type Daemon struct { | |||
// fusedev shared mode: zero, one or more RAFS instances | |||
// fscache shared mode: zero, one or more RAFS instances | |||
Instances rafsSet | |||
authCache *lru.Cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auth should be shared among different nydusd daemons. So why to bind the cache to a single nydusd daemon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Move it to the manager.
pkg/daemon/daemon.go
Outdated
@@ -151,6 +158,31 @@ func (d *Daemon) RemoveInstance(snapshotID string) { | |||
d.DecRef() | |||
} | |||
|
|||
func (d *Daemon) UpdateAuth(imageHost, auth string) error { | |||
key, err := keyring.Add(imageHost, auth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to consider the atomicity when updating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/daemon/daemon.go
Outdated
} | ||
|
||
data, err := keyring.Search(imageHost) | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if err is nil looks strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
This approach seems to only solve the nydusd registry credential persistence problem, but when the credential is changed (e.g. registry user/pass dynamically generated by a credential helper), nydusd may not be able to timely detect the update. I think #504 is a better implementation. |
30ee1e2
to
25b9d09
Compare
I believe this PR does not conflict with #504. It is better to get authentication from the credential server if |
92d4b96
to
e79e344
Compare
pkg/auth/cache.go
Outdated
|
||
import ( | ||
"github.com/pkg/errors" | ||
"k8s.io/utils/lru" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we have used github.com/golang/groupcache/lru
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
pkg/auth/keyring.go
Outdated
lock *sync.RWMutex | ||
} | ||
|
||
func NewKeyRing() *KeyRing { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe give some unit test cases for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, please try to add some unit test, especially for keying garbage collection and if the boundary is correctly handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -192,6 +199,25 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool) | |||
|
|||
cmd := exec.Command(nydusdPath, args...) | |||
|
|||
if config.IsKeyringEnabled() && !d.IsSharedDaemon() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we support shared daemon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it calls c.FillAuth(keyChain)
to fill auth before sending mount request to nydus daemon.
e79e344
to
44b5fee
Compare
ee9c16d
to
a9c1dd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also have an e2e test case defined in integration/entrypoint.sh
c.FillAuth(keyChain) | ||
if config.IsKeyringEnabled() && fn != nil { | ||
if err := fn(registryHost, keyChain); err != nil { | ||
if errors.Is(err, unix.EINVAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error type should be transparent for the caller
Signed-off-by: Bin Tang <[email protected]>
a9c1dd0
to
c317c16
Compare
auth
fornydusd
in the keyring instead of the configuration file.auth
via environment variable to avoid displaying it in command parameter.Related to dragonflyoss/nydus#1381 and dragonflyoss/nydus#1382