Commit graph

49 commits

Author SHA1 Message Date
Mark Johnston
667ef8875b nuageinit: Add wrappers for chmod and chown
In the wrappers, check for errors and abort if one is raised.  At some
point it may be useful to have a mechanism to ignore errors, but I'm not
sure yet how that should look.

For chmod, let the mode be specified as an octal number, otherwise it's
hard to understand what's happening.  Note that this must be specified
as a string, otherwise tonumber() will raise an error.

Reviewed by:	bapt
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D51159
2025-07-05 14:54:07 +00:00
Baptiste Daroussin
b56d2195f1 nuageinit: enhance sudo support
from the cloudinit specification sudo rules can be a string or an
array of string
2025-06-26 14:34:51 +02:00
Baptiste Daroussin
3969965c7f nuageinit: fix setting owner when only the user is set 2025-06-26 14:34:51 +02:00
Baptiste Daroussin
d9a4c24df1 nuageinit: write_files fix typo breaking tests 2025-06-26 14:34:51 +02:00
Baptiste Daroussin
19a7ea3cc4 nuageinit: implement write_files
write_files is a list of files that should be created at the first boot

each file content can be either plain text or encoded in base64 (note
that cloudinit specify that gzip is supported, but we do not support it
yet.)

All other specifier from cloudinit should work:
by default all files will juste overwrite exesiting files except if
"append" is set to true, permissions, ownership can be specified.
The files are create before packages are being installed and user
created.

if "defer" is set to true then the file is being created after packages
installation and package manupulation.

This feature is requested for KDE's CI.
2025-06-26 13:47:37 +02:00
Baptiste Daroussin
40dafa08b2 nuageinit: use lyaml to parse yaml files
This fixes case where vendors or cloudinit consumers are using all
features from yaml.

KDE is using reference for its CI for example.
lima-vm uses syntax for which our previous yaml.lua has bug in the
parser (https://github.com/lima-vm/lima/issues/1508)
2025-06-26 09:24:15 +02:00
Siva Mahadevan
7067bab893
nuageinit(7) tests: Fix extra space in test output expectation
This fixes the test case libexec.nuageinit.nuageinit.config2_userdata_packages

Signed-off-by: Siva Mahadevan <me@svmhdvn.name>

Event:		Kitchener-Waterloo Hackathon 202506
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1734
2025-06-20 17:01:25 -04:00
Maxim Konovalov
b78b7fa01f nuageinit.7: language and grammar improvements
Reviewed by:	bapt
2025-06-19 13:14:33 +00:00
Maxim Konovalov
1049c079c0 nuageinit.7: language and grammar fixes mostly 2025-06-17 07:59:57 +00:00
Baptiste Daroussin
5ec727ea1a nuageinit: write a documentation
Reviewed by:	imp, ziaee (both a previous version)
Differential Revision:	https://reviews.freebsd.org/D50878
2025-06-17 08:54:39 +02:00
Baptiste Daroussin
dba559e806 nuageinit: fix typo 2025-06-16 15:52:47 +02:00
Baptiste Daroussin
2a05d577ab nuageinit: add a post network script
refactor nuageinit to allow a 3rd execution point during boot:
1. nuageinit is invoked before NETWORKING with a minimalistic network setup
   for openstrack and potentially other network config setup. it tries
   to configure everything which is not requiring any network.
2. nuageinit is invoked again post NETWORKING but pre SERVERS, in the
   phase it does all that requires network, like dealing with packages.
   Note that creating users have been moved to this phase to allow the
   installation of shells like bash or zsh prior the creation of the
   users, before that the user creation was failing if a non installed
   shell was requested.
3. nuageinit will execute at the rc.local time all the specified scripts
   and commands.

MFC After: 1 week
2025-06-16 10:29:19 +02:00
Baptiste Daroussin
6a54f886be nuageinit: add support for sudo 2025-06-15 17:18:48 +02:00
Baptiste Daroussin
f1dd507b2c nuageinit: support "fqdn" and "hostname" 2025-06-14 20:56:59 +02:00
Baptiste Daroussin
f678c47590 nuageinit: pet luacheck
Rename path into ni_path (ni stands for nuageinit) which is more
understandable and avoid a shadowing warning because we also use a
variable named path later.

Add a missing local
2025-06-10 11:32:06 +02:00
Baptiste Daroussin
8feca60d6e nuageinit: runcmd should also be executed late
Execute the runcmd specified in cloudinit at the same moment as the
user_data script aka late in the boot process, to respect cloudinit
specifications
2025-06-10 11:28:49 +02:00
Baptiste Daroussin
09545628f0 nuageinit: fix using user_data as a script
In official cloudinit, when a user_data file starts with '#!' it
should be execute late in the boot process. To respect this nuageinit
now copy the user_data script into a /var/cache/nuageinit/user_data if
found and a new "firsboot" rcscript anchored to the 'local' rc script is
responsible to execute it if found.

Note by doing this, we fix another issue we had with nuageinit, if the
cloudinit provider provides the user_data scriptout with the executable
permission, previous implementation was not working, like apparently
what Digital Ocean is doing.

PR:		287183
Reported by:	olgeni@
2025-06-10 09:20:23 +02:00
Sebastien Baylocq
682af9601a nuageinit: more package related functions
Implement package_update and package_upgrade, which allows to launch
an update of the metadata and an upgrade of the packages.

Sponsored by:	OVHCloud
2025-06-06 18:26:41 +02:00
Sebastien Baylocq
076fec1b88 nuageinit: implement packages
Installs a list of packages

Sponsored by:	OVHCloud
2025-06-06 18:26:40 +02:00
Sebastien Baylocq
43b82d69b2 nuageinit: add a function to bootstrap pkg if needed
Sponsored by:	OVHCloud
2025-06-06 18:26:38 +02:00
Sebastien Baylocq
2f35a52183 nuageinit: implement runcmd
runcmd contains a list of string, each item will be executed in order.

Sponsored by:	OVHCloud
2025-06-06 18:26:37 +02:00
Sebastien Baylocq
e38f521f53 nuageinit: helper function to setup adduser
To carry out the userdata unit tests, you need to set up the environment in
order to skip adding the default user (nuage.adduser(default_user)

Sponsored by:	OVHCloud
2025-06-06 18:26:35 +02:00
Baptiste Daroussin
c201a1198a nuageinit: implement chpasswd
Add support for chpasswd, with all possible syntaxes, including
deprecated one: chpasswd.list as a list or as a multiline string
as some providers are still only providing this deprecated form

Sponsored by:	OVHCloud
MFC After:	1 week
Reviewed by:	kevans, jlduran
Differential Revision: 	https://reviews.freebsd.org/D50021
2025-04-30 09:32:06 +02:00
Baptiste Daroussin
18d74dc0cd nuageinit: fix luacheck nit
Reported by:	jlduran
2025-04-23 16:49:46 +02:00
Baptiste Daroussin
f85d086827 nuageinint: implement ssh_pwauth
ssh_pwauth sets the value in sshd_config for the password authentication
This implementation tries to avoid touching the file if cloudinit
request for what is already the default value.

MFC After:	3 days
Sponsored by:	OVHCloud
Reviewed by:	kevans, jlduran
Differential Revision:	https://reviews.freebsd.org/D49875
2025-04-23 16:29:02 +02:00
Baptiste Daroussin
f3b371f4d9 nuageinit: remove redundant mkdirs 2024-11-27 10:03:06 +01:00
Baptiste Daroussin
41fe9d5300 nuageinit: implement ssh_keys support
MFC After:	1 week
Sponsored by:	OVHCloud
2024-11-27 09:53:04 +01:00
Baptiste Daroussin
3e2a7a2cbe nuageinit: add test about encrypted passwords
While here fix fc34a2463c where the
adduser_passwd.lua file was not added
2024-11-20 11:02:55 +01:00
Baptiste Daroussin
3e50286607 nuageinit: use io.popen instead of pipes in shell for password
using echo in a sh(1) command line, requires many escaping to be done
right, using io.popen we don't need to do this escaping anymore.
2024-11-20 10:41:46 +01:00
Baptiste Daroussin
fc34a2463c nuageinit: add test for the password 2024-11-20 10:41:46 +01:00
Simon J. Gerraty
a64729f507 Update Makefile.depend files
After building packages we have a number of new
and updated Makefile.depend files

Reviewed by:	stevek
2024-10-14 10:26:17 -07:00
Jose Luis Duran
e72457c4f5 nuageinit: tests: Cleanup
- Export NUAGE_FAKE_ROOTDIR only once
- Use the header section of the test to require the root user
- Use the PWD environment variable
- Set the root/sys shell as /bin/sh
- Use RFC 5737 reserved IP addresses

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 13:00:16 +02:00
Jose Luis Duran
b9ce743c54 nuageinit: Fix passwords
The hashed password usually contains a "$" sign, which, when used on a
shell, must be escaped.  Also, the plain text password may contain
special characters that require escaping.

Add a quick fix by enclosing it in single quotes.  Note that if the
plain text password contains a "'", it will still fail.  This will be
properly fixed in later commits.

Some here documents require the document to be a string literal,
especially when passing invalid characters.  Enclose it in single
quotes.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:59:56 +02:00
Jose Luis Duran
38bb6f79e3 nuageinit: Standardize user-facing error messages
Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:59:24 +02:00
Jose Luis Duran
945632ca76 nuageinit: Standardize warning/error messages
Standardize the utilities from nuage.lua, to return nil on failure, plus
an error message as a second result, and some value different from nil
on success.

Make warnmsg() and errmsg() append "nuageinit: " by default.  Pass an
optional second parameter as false to avoid printing this tag.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:59:14 +02:00
Jose Luis Duran
9b2d92addc nuageinit: Replace os.execute with Lua libraries
Prefer posix.sys.stat's chmod() to os.execute().  While here, change the
name of the locals to be more descriptive.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:59:00 +02:00
Jose Luis Duran
504981357a nuageinit: Lua check and lint files
Mostly white space, style, and luacheck compliance.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:58:00 +02:00
Baptiste Daroussin
a6ecbf2b35 nuageinit: improve debugging when mkdir fails 2024-08-20 12:09:43 +02:00
Baptiste Daroussin
19fb9ad746 nuageinit: readd ssh key parsing when key is in meta_data.json
in openstack when no user is specified but a sshkey is provided
the information is stored in meta_data.json under "public_keys"

PR:	280461
Reported by:	tdb
2024-08-20 12:08:29 +02:00
Jose Luis Duran
8edd6c07c8 nuageinit: Fix tests
Commit 07d17ca189 set the recommended
permissions for the SSH authorized keys file and directory.  The tests,
however, were failing on CI.

Use stat to check for the proper permissions.

Fixes:	07d17ca189 nuageinit: Set recommended SSH permissions
Reported by:	Jenkins
2024-07-25 11:15:29 +02:00
Jose Luis Duran
7aecd689e3 nuageinit: Fix the homedir variable name
cloud-init uses homedir, not home.
2024-07-25 11:15:29 +02:00
Jose Luis Duran
07d17ca189 nuageinit: Set recommended SSH permissions
As stated in sshd(8), the recommended permissions for ~/.ssh are
read/write/execute for the user, and not accessible by others; and the
recommended permissions for ~/.ssh/authorized_keys are read/write for
the user, and not accessible by others.
2024-07-23 15:02:28 +02:00
Jose Luis Duran
7b73ecfe64 nuageinit: Accept plain text passwords
Per pw(8), when -H is set, the password should be supplied already
encrypted in a form suitable for writing directly to the password
database (passwd in cloud-init tems); -h provides a special interface by
which interactive scripts can set an account password using pw(8) in
plain text (plain_text_passwd in cloud-init terms).

The default user (freebsd) is defined with a plain_text_passwd
(freebsd), not with an encrypted one.
2024-07-23 15:01:54 +02:00
Baptiste Daroussin
cde6642431 nuageinit: check for both user_data and user-data
openstack, ec2 and other implementation of cloudinit disagrees on the
name of the file "user-data" or "user_data", test both and use the first
found

PR:	279876
2024-06-27 10:32:14 +02:00
Baptiste Daroussin
8d7331e62a nuageinit: fix authorized_key test
After miss reading the cloudinit spec I ended up writting a wrong
test for basic ssh key setup, nuageinit has been fixed, but not
the test, here is the actual fix.

Reported by:	markj
2024-06-05 11:00:54 +02:00
Baptiste Daroussin
fa07b02f6e nuageinit: make addsshkey friendly for testsuite 2024-06-05 11:00:53 +02:00
Baptiste Daroussin
83fcab792c nuageinit: use pw(8) instead of getent(1)
pw(8) allows to seek for users in a custom rootdir, which makes it
easier for a testsuite

MFC After:	3 days
2024-06-05 11:00:53 +02:00
Jeremy Collin
48edad2edf fix (nuageinit): SSH keys are not handled in metadata but in userdata
MFC After: 1 day
2024-05-21 16:52:42 +02:00
Baptiste Daroussin
a42d6f7601 nuageinit: add basic support for cloudinit.
this is a very early script to support cloudinit, it does not intend to
be a full featured cloudinit client, but will support a good enough
subset to be viable in most case.

It support nocloud and openstack config-2 config drive mode (iso9660 or
msdosfs)

The following features are currently supported:
- adding users (including a default user named 'freebsd' with password
  'freebsd'
- adding groups
- adding ssh keys
- static ipv4, static ipv6, dynamic ipv4

With this one is able to use the 'bring your own image feature" out of
box.

It is expected that the script grows the support of other clouds
supporting cloud-init, contributions are welcomed.

It is designed to be only run once via the firstboot mecanism.

Sponsored by:	OVHCloud
MFC After:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D44141
2024-03-15 09:22:16 +01:00