Commit graph

21 commits

Author SHA1 Message Date
Baptiste Daroussin
68f025feeb 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.

(cherry picked from commit 3e502866073f8d922eecb9016920a56b90c35e38)
2025-01-15 10:53:39 +01:00
Baptiste Daroussin
707a34afe1 nuageinit: remove redundant mkdirs
(cherry picked from commit f3b371f4d938c09c4cdc8fd95b4b52e1d8dd41dd)
2025-01-15 10:51:27 +01:00
Baptiste Daroussin
c062d3ec60 nuageinit: implement ssh_keys support
MFC After:	1 week
Sponsored by:	OVHCloud

(cherry picked from commit 41fe9d53005ef213ff16d9b095c0a88e3f2fb296)
2024-12-12 16:52:25 +01:00
Jose Luis Duran
e573007af2 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>
(cherry picked from commit e72457c4f5166eef2a27249e02f3c1e9a1cf852d)
2024-10-08 09:04:02 +02:00
Jose Luis Duran
9881d68b1e 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>
(cherry picked from commit b9ce743c5447e90c2c97f4d49e048c301f708527)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
03abe3ac40 nuageinit: Standardize user-facing error messages
Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 38bb6f79e39a14ea99f559f59129a4cadf92b569)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
182ff41e84 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>
(cherry picked from commit 945632ca76117029e7bd1f46d17ccb378973daf7)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
1eaf3331ea 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>
(cherry picked from commit 9b2d92addc31ba6f5696c85d184a45d43e9073dc)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
68c7c28d0e nuageinit: Lua check and lint files
Mostly white space, style, and luacheck compliance.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 504981357aa36365784458cfe8d9e23097bfac7b)
2024-10-08 09:04:01 +02:00
Baptiste Daroussin
701ac3adcb nuageinit: improve debugging when mkdir fails
(cherry picked from commit a6ecbf2b35856e312d1e826b206142b9f930a760)
2024-09-03 09:05:25 +02:00
Baptiste Daroussin
3a73c77f2d 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

(cherry picked from commit 19fb9ad746517c7af9d79a982334b2550f285355)
2024-09-03 09:05:24 +02:00
Jose Luis Duran
5f7256579c nuageinit: Fix tests
Commit 07d17ca189fcf3cc44b7706040b05ca8135c3b85 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:	07d17ca189f nuageinit: Set recommended SSH permissions
Reported by:	Jenkins

(cherry picked from commit 8edd6c07c8dafcc5828bceb5fea0684c7d0d0775)
2024-09-03 09:05:24 +02:00
Jose Luis Duran
3dbc333a9e nuageinit: Fix the homedir variable name
cloud-init uses homedir, not home.

(cherry picked from commit 7aecd689e362330a035a199afbe5707a8c4edc9c)
2024-09-03 09:05:24 +02:00
Jose Luis Duran
6171791787 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.

(cherry picked from commit 07d17ca189fcf3cc44b7706040b05ca8135c3b85)
2024-09-03 09:05:24 +02:00
Jose Luis Duran
c7887c8e2e 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.

(cherry picked from commit 7b73ecfe648487c7706ac2b854dcf1435e60e4ca)
2024-09-03 09:05:24 +02:00
Baptiste Daroussin
28094582f0 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
(cherry picked from commit cde6642431bb0ca21aeebc7c521e99c681d31ffb)
2024-09-03 09:05:24 +02:00
Baptiste Daroussin
30346359b3 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

(cherry picked from commit 8d7331e62a5aa75760ac54e3cb1594b0001645c6)
2024-06-27 10:56:17 +02:00
Baptiste Daroussin
3cfc085f8a nuageinit: make addsshkey friendly for testsuite
(cherry picked from commit fa07b02f6e09f776b3afe5709e8fee1764c11a2a)
2024-06-27 10:55:07 +02:00
Baptiste Daroussin
12e584c11e 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

(cherry picked from commit 83fcab792c9d7f13f7e8bd73cf1850ba74f49341)
2024-06-27 10:55:06 +02:00
Jeremy Collin
5601feb720 fix (nuageinit): SSH keys are not handled in metadata but in userdata
MFC After: 1 day

(cherry picked from commit 48edad2edf6eb7a539e40dad8e1f87e3fa4973fd)
2024-05-22 08:51:33 +02:00
Baptiste Daroussin
16a6da44e2 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
Differential Revision:	https://reviews.freebsd.org/D44141

(cherry picked from commit a42d6f76018e4ed8324e319ab48aac904bda437c)
(cherry picked from commit c051f22bce42d920abba61bd7cf4ef5b6a270ffa)
(cherry picked from commit b8c053c9a612651d4909f7a323088f3e92485b7b)
(cherry picked from commit 9eae9233fdcc946945f4191e1413f548adfa2943)
2024-04-11 13:52:52 +02:00