Commit graph

24 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
6a54f886be nuageinit: add support for sudo 2025-06-15 17:18:48 +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
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
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
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
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
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
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
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