From ba3c24e1c3c5a0081a87c6b32b4d11a60b6b6564 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Tue, 2 Jul 2024 15:15:19 +0200 Subject: [PATCH 1/2] ignore +:: style lines in passwd/group The lines +::::: or +::: are used in passwd/group as placeholer for users added form the network via ldap/nis/sssd. These lines should not trigger a warning. Signed-off-by: Christian Goll --- CHANGELOG.md | 4 ++++ internal/pkg/container/syncuids.go | 6 ++++-- internal/pkg/container/syncuids_test.go | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fffdf0c..a15324d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix the issue that new files created with wwctl overlay edit have 755 permissions. #1236 - Mount `/sys` and `/run` during `wwctl container exec`. #1287 +### Changed + +- Ignore +:::: lines in passwd/group during syncuser. #1286 + ## v4.5.4, 2024-06-12 ### Fixed diff --git a/internal/pkg/container/syncuids.go b/internal/pkg/container/syncuids.go index 211567e7..74581e02 100644 --- a/internal/pkg/container/syncuids.go +++ b/internal/pkg/container/syncuids.go @@ -176,13 +176,15 @@ func (db syncDB) read(fileName string, fromContainer bool) error { if name == "" { continue } - + // ignore ldap/nis/sssd line + if fields[0] == "+" { + continue + } id, err := strconv.Atoi(fields[2]) if err != nil { wwlog.Warn("Ignoring line %s (parse error)", line) continue } - entry, ok := db[name] if !ok { entry = syncInfo{HostID: -1, ContainerID: -1} diff --git a/internal/pkg/container/syncuids_test.go b/internal/pkg/container/syncuids_test.go index abaad68a..86242f5a 100644 --- a/internal/pkg/container/syncuids_test.go +++ b/internal/pkg/container/syncuids_test.go @@ -1,10 +1,12 @@ package container import ( + "bytes" "os" "testing" "github.com/stretchr/testify/assert" + "github.com/warewulf/warewulf/internal/pkg/wwlog" ) func writeTempFile(t *testing.T, input string) string { @@ -268,3 +270,16 @@ func Test_malformed_passwd(t *testing.T) { err := db.readFromHost(hostFileName) assert.NoError(t, err) } + +func Test_network_passwd(t *testing.T) { + buf := new(bytes.Buffer) + wwlog.SetLogWriter(buf) + hostInput := `testuser1:x:1001:1001::/home/testuser:/bin/bash ++::::::` + hostFileName := writeTempFile(t, hostInput) + defer os.Remove(hostFileName) + db := make(syncDB) + err := db.readFromHost(hostFileName) + assert.NotContains(t, buf.String(), "parse error") + assert.NoError(t, err) +} From 0b765d242a970ccb658433a33defd566658ff219 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Tue, 2 Jul 2024 14:34:19 -0600 Subject: [PATCH 2/2] Extend new syncuser handling for +/- entries Since these lines are being omitted in the final sync'd passwd/group file, a new message indicates that the line is being skipped; but it is no longer denoted as a parse error. Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 2 +- internal/pkg/container/syncuids.go | 3 ++- internal/pkg/container/syncuids_test.go | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a15324d7..bbcf4532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed -- Ignore +:::: lines in passwd/group during syncuser. #1286 +- Explicitly ignore compat-style NIS lines in passwd/group during syncuser. #1286 ## v4.5.4, 2024-06-12 diff --git a/internal/pkg/container/syncuids.go b/internal/pkg/container/syncuids.go index 74581e02..7bb19153 100644 --- a/internal/pkg/container/syncuids.go +++ b/internal/pkg/container/syncuids.go @@ -177,7 +177,8 @@ func (db syncDB) read(fileName string, fromContainer bool) error { continue } // ignore ldap/nis/sssd line - if fields[0] == "+" { + if strings.HasPrefix(fields[0], "+") || strings.HasPrefix(fields[0], "-") { + wwlog.Verbose("Ignoring line %s (unhandled compat-style NIS reference)", line) continue } id, err := strconv.Atoi(fields[2]) diff --git a/internal/pkg/container/syncuids_test.go b/internal/pkg/container/syncuids_test.go index 86242f5a..efd3c6f3 100644 --- a/internal/pkg/container/syncuids_test.go +++ b/internal/pkg/container/syncuids_test.go @@ -275,11 +275,13 @@ func Test_network_passwd(t *testing.T) { buf := new(bytes.Buffer) wwlog.SetLogWriter(buf) hostInput := `testuser1:x:1001:1001::/home/testuser:/bin/bash -+::::::` ++:::::: +-::::::` hostFileName := writeTempFile(t, hostInput) defer os.Remove(hostFileName) db := make(syncDB) err := db.readFromHost(hostFileName) assert.NotContains(t, buf.String(), "parse error") + assert.Contains(t, buf.String(), "Ignoring line") assert.NoError(t, err) }