Skip to content
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

Backport/v2.2 parse image pull auth from env #1383

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ impl ConfigV2 {
false
}
}

/// Fill authorization for registry backend.
pub fn update_registry_auth_info(&mut self, auth: &Option<String>) {
if let Some(auth) = auth {
if let Some(backend) = self.backend.as_mut() {
if let Some(registry) = backend.registry.as_mut() {
registry.auth = Some(auth.to_string());
}
}
}
}
}

impl FromStr for ConfigV2 {
Expand Down Expand Up @@ -1895,4 +1906,48 @@ mod tests {
assert_eq!(&config.id, "id1");
assert_eq!(config.backend.as_ref().unwrap().backend_type, "localfs");
}

#[test]
fn test_update_registry_auth_info() {
let config = r#"
{
"device": {
"id": "test",
"backend": {
"type": "registry",
"config": {
"readahead": false,
"host": "docker.io",
"repo": "library/nginx",
"scheme": "https",
"proxy": {
"fallback": false
},
"timeout": 5,
"connect_timeout": 5,
"retry_limit": 8
}
}
},
"mode": "direct",
"digest_validate": false,
"enable_xattr": true,
"fs_prefetch": {
"enable": true,
"threads_count": 10,
"merging_size": 131072,
"bandwidth_rate": 10485760
}
}"#;

let mut rafs_config = ConfigV2::from_str(&config).unwrap();
let test_auth = "test_auth".to_string();

rafs_config.update_registry_auth_info(&Some(test_auth.clone()));

let backend = rafs_config.backend.unwrap();
let registry = backend.registry.unwrap();
let auth = registry.auth.unwrap();
assert_eq!(auth, test_auth);
}
}
5 changes: 4 additions & 1 deletion docs/nydusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ sudo nydusd \
--log-level info
```

For registry backend, we can set authorization with environment variable `IMAGE_PULL_AUTH` to avoid loading `auth` from nydusd configuration file.

### Run With Virtio-FS
If no `/path/to/bootstrap` is available, please refer to [nydus-image.md](https://github.com/dragonflyoss/image-service/blob/master/docs/nydus-image.md) for more details.

Expand Down Expand Up @@ -227,7 +229,8 @@ Document located at: https://github.com/adamqqqplay/nydus-localdisk/blob/master/
},
...
}
```
```
Note: The value of `device.backend.config.auth` will be overwrite if running the nydusd with environment variable `IMAGE_PULL_AUTH`.

##### Enable P2P Proxy for Storage Backend

Expand Down
13 changes: 11 additions & 2 deletions src/bin/nydusd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use nix::sys::signal;
use rlimit::Resource;

use nydus::{get_build_time_info, SubCmdArgs};
use nydus_api::BuildTimeInfo;
use nydus_api::{BuildTimeInfo, ConfigV2};
use nydus_app::{dump_program_info, setup_logging};
use nydus_service::daemon::DaemonController;
use nydus_service::{
Expand Down Expand Up @@ -423,7 +423,16 @@ fn process_fs_service(
)
}
None => match args.value_of("config") {
Some(v) => std::fs::read_to_string(v)?,
Some(v) => {
let auth = std::env::var("IMAGE_PULL_AUTH").ok();
if auth.is_some() {
let mut config = ConfigV2::from_file(v)?;
config.update_registry_auth_info(&auth);
serde_json::to_string(&config)?
} else {
std::fs::read_to_string(v)?
}
}
None => {
let e = NydusError::InvalidArguments(
"both --config and --localfs-dir are missing".to_string(),
Expand Down