gluon-authorized-keys: add unauthorized_keys to remove access
This commit is contained in:
		
							parent
							
								
									1780bafafc
								
							
						
					
					
						commit
						c4ab768f4b
					
				| @ -1 +1,2 @@ | |||||||
| need_string_array(in_site({'authorized_keys'})) | need_string_array(in_site({'authorized_keys'})) | ||||||
|  | need_string_array(in_site({'unauthorized_keys'}), false) | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ local site = require 'gluon.site' | |||||||
| local file = '/etc/dropbear/authorized_keys' | local file = '/etc/dropbear/authorized_keys' | ||||||
| 
 | 
 | ||||||
| local keys = {} | local keys = {} | ||||||
|  | local rm_keys = {} | ||||||
| 
 | 
 | ||||||
| local function load_keys() | local function load_keys() | ||||||
| 	for line in io.lines(file) do | 	for line in io.lines(file) do | ||||||
| @ -11,12 +12,21 @@ local function load_keys() | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | for _, key in ipairs(site.unauthorized_keys({})) do | ||||||
|  | 	rm_keys[key] = true | ||||||
|  | end | ||||||
|  | 
 | ||||||
| pcall(load_keys) | pcall(load_keys) | ||||||
| 
 | 
 | ||||||
| local f = io.open(file, 'a') | local f = io.open(file, 'w') | ||||||
| for _, key in ipairs(site.authorized_keys()) do | for _, key in ipairs(site.authorized_keys()) do | ||||||
| 	if not keys[key] then | 	if not keys[key] then | ||||||
| 		f:write(key .. '\n') | 		f:write(key .. '\n') | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  | for key, _ in pairs(keys) do | ||||||
|  | 	if not rm_keys[key] then | ||||||
|  | 		f:write(key .. '\n') | ||||||
|  | 	end | ||||||
|  | end | ||||||
| f:close() | f:close() | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user