-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright 2018 CoreOS, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package systemd | ||
|
||
import ( | ||
"github.com/coreos/ignition/v2/tests/register" | ||
"github.com/coreos/ignition/v2/tests/types" | ||
) | ||
|
||
func init() { | ||
register.Register(register.NegativeTest, CreateSystemdUserServiceNouser()) | ||
} | ||
|
||
func CreateDefaultDisk(Disk []types.Disk) []types.Disk { | ||
Disk[0].Partitions.AddFiles("ROOT", []types.File{ | ||
{ | ||
Node: types.Node{ | ||
Name: "passwd", | ||
Directory: "etc", | ||
}, | ||
Contents: "root:x:0:0:root:/root:/bin/bash\ncore:x:500:500:CoreOS Admin:/home/core:/bin/bash\nsystemd-coredump:x:998:998:systemd Core Dumper:/:/sbin/nologin\nfleet:x:253:253::/:/sbin/nologin\n", | ||
}, | ||
{ | ||
Node: types.Node{ | ||
Name: "shadow", | ||
Directory: "etc", | ||
}, | ||
Contents: "root:*:15887:0:::::\ncore:*:15887:0:::::\nsystemd-coredump:!!:17301::::::\nfleet:!!:17301::::::\n", | ||
}, | ||
{ | ||
Node: types.Node{ | ||
Name: "group", | ||
Directory: "etc", | ||
}, | ||
Contents: "root:x:0:root\nwheel:x:10:root,core\nsudo:x:150:\ndocker:x:233:core\nsystemd-coredump:x:998:\nfleet:x:253:core\ncore:x:500:\nrkt-admin:x:999:\nrkt:x:251:core\n", | ||
}, | ||
{ | ||
Node: types.Node{ | ||
Name: "gshadow", | ||
Directory: "etc", | ||
}, | ||
Contents: "root:*::root\nusers:*::\nsudo:*::\nwheel:*::root,core\nsudo:*::\ndocker:*::core\nsystemd-coredump:!!::\nfleet:!!::core\nrkt-admin:!!::\nrkt:!!::core\ncore:*::\n", | ||
}, | ||
{ | ||
Node: types.Node{ | ||
Name: "nsswitch.conf", | ||
Directory: "etc", | ||
}, | ||
Contents: "# /etc/nsswitch.conf:\n\npasswd: files\nshadow: files\ngroup: files\n\nhosts: files dns myhostname\nnetworks: files dns\n\nservices: files\nprotocols: files\nrpc: files\n\nethers: files\nnetmasks: files\nnetgroup: files\nbootparams: files\nautomount: files\naliases: files\n", | ||
}, | ||
{ | ||
Node: types.Node{ | ||
Name: "login.defs", | ||
Directory: "etc", | ||
}, | ||
Contents: `MAIL_DIR /var/spool/mail | ||
PASS_MAX_DAYS 99999 | ||
PASS_MIN_DAYS 0 | ||
PASS_MIN_LEN 5 | ||
PASS_WARN_AGE 7 | ||
UID_MIN 1000 | ||
UID_MAX 60000 | ||
SYS_UID_MIN 201 | ||
SYS_UID_MAX 999 | ||
GID_MIN 1000 | ||
GID_MAX 60000 | ||
SYS_GID_MIN 201 | ||
SYS_GID_MAX 999 | ||
CREATE_HOME yes | ||
UMASK 077 | ||
USERGROUPS_ENAB yes | ||
ENCRYPT_METHOD SHA512 | ||
`, | ||
}, | ||
}) | ||
return Disk | ||
} | ||
|
||
func CreateSystemdUserServiceNouser() types.Test { | ||
name := "systemd.unit.userunit.wronguser" | ||
in := CreateDefaultDisk(types.GetBaseDisk()) | ||
out := in | ||
config := `{ | ||
"passwd": { | ||
"users": [{ | ||
"name": "tester1" | ||
} | ||
] | ||
}, | ||
"ignition": { | ||
"version": "$version" | ||
}, | ||
"systemd": { | ||
"units": [ | ||
{ | ||
"contents": "[Unit]\nDescription=promtail.service\n[Install]\nWantedBy=multi-user.target default.target", | ||
"enabled": true, | ||
"name": "unit1.service", | ||
"scope": "user", | ||
"users" : ["tester2"] | ||
} | ||
] | ||
} | ||
}` | ||
|
||
configMinVersion := "3.4.0-experimental" | ||
|
||
return types.Test{ | ||
Name: name, | ||
In: in, | ||
Out: out, | ||
Config: config, | ||
ConfigMinVersion: configMinVersion, | ||
} | ||
} |
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