Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gluon-authorized-keys: add unauthorized_keys to remove access #2782

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/features/authorized-keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ If you select this package, add a list of authorized keys to ``site.conf`` like
...

Existing keys in ``/etc/dropbear/authorized_keys`` will be preserved.

If you want to remove specific keys in the future, specify them like this:::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take note here that this will also remove SSH key which are originally added by the user.


{
unauthorized_keys = { 'ssh-rsa AAA.... user1@host',
'ssh-rsa AAA.... user2@host' },
authorized_keys = { 'ssh-rsa AAA.... user3@host',
'ssh-rsa AAA.... user4@host' },
hostname_prefix = ...
...
1 change: 1 addition & 0 deletions package/gluon-authorized-keys/check_site.lua
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
need_string_array(in_site({'authorized_keys'}))
need_string_array(in_site({'unauthorized_keys'}), false)
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ local site = require 'gluon.site'
local file = '/etc/dropbear/authorized_keys'

local keys = {}
local rm_keys = {}

local function load_keys()
for line in io.lines(file) do
keys[line] = true
end
end

for _, key in ipairs(site.unauthorized_keys({})) do
rm_keys[key] = true
end

pcall(load_keys)

local f = io.open(file, 'a')
local f = io.open(file, 'w')
for _, key in ipairs(site.authorized_keys()) do
if not keys[key] then
f:write(key .. '\n')
end
end
for key, _ in pairs(keys) do
if not rm_keys[key] then
f:write(key .. '\n')
end
end
f:close()