-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
group commands for users and servers
- Loading branch information
Sam Ban
committed
Sep 4, 2021
1 parent
faa0e5e
commit c429ab0
Showing
10 changed files
with
203 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Develop Test | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- wip | ||
|
||
jobs: | ||
Test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Checkout submodules | ||
uses: textbook/git-checkout-submodule-action@master | ||
with: | ||
remote: true | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: '1.17.x' | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# SSH Manager - manage authorized_key file on remote servers | ||
|
||
This is a simple tool that I came up after having to on-boarding and off-boarding developers on a | ||
very colourful palette of environments from AWS to 3rd party hosting providers. | ||
This is a simple tool that I came up after having to on-boarding and off-boarding developers on a very colourful palette of environments from AWS to 3rd party hosting providers. | ||
|
||
As every one of my creations this tool is solving _my_ problem. It does not warranty your problem will be solved, | ||
but in that highly unlikely event please let me know, fixes and pull requests, issues are all very welcome without | ||
again the promise that I'll do anything, I'm normally really busy, apologies. | ||
As every one of my creations this tool is solving _my_ problem. It does not warranty your problem will be solved, but in that highly unlikely event please let me know, fixes and pull requests, issues are all very welcome without again the promise that I'll do anything, I'm normally really busy, apologies. | ||
|
||
**Caution**: Plan your group memberships carefully, keep your management key out of any groups so you don't accidentally remove management key from any server, locking yourself out. | ||
|
||
## Installation | ||
|
||
|
@@ -137,6 +136,19 @@ $ ./sshman rename user [email protected] [email protected] | |
$ ./sshman rename server oldalias newalias | ||
``` | ||
|
||
### Modifying user and server groupping | ||
|
||
Modify user's groups, or remove groups from user to allow global access: | ||
```sh | ||
$ ./sshman groups user [email protected] group1 group2 | ||
``` | ||
|
||
Modify server groups or remove from all groups: | ||
```sh | ||
$ ./sshman groups server serveralias group1 group2 | ||
``` | ||
Note: Removing server from a group will remove all users that are on the server only because of that group. If the server is in another group, the users that are in both groups will not be removed. | ||
|
||
### (Possible) Future Plans | ||
|
||
- [x] Reuse stored ssh key for modifying user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsCmd represents the groups command | ||
var groupsCmd = &cobra.Command{ | ||
Use: "groups", | ||
Short: "Modify user or server groups", | ||
Long: `Modify user's groups, or remove groups from user to allow global access: | ||
$ ./sshman groups user [email protected] group1 group2 | ||
Modify server groups or remove from all groups: | ||
$ ./sshman groups server serveralias group1 group2 | ||
`, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(groupsCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/shoobyban/sshman/backend" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsServerCmd represents the user group editing command | ||
var groupsServerCmd = &cobra.Command{ | ||
Use: "server", | ||
Short: "Modify group assignments for a server", | ||
Long: `Modify server groups or remove from all groups: | ||
$ ./sshman groups server serveralias group1 group2 | ||
`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
cfg := backend.ReadConfig(backend.NewSFTP()) | ||
if len(args) < 1 { | ||
return | ||
} | ||
email := args[0] | ||
groups := args[1:] | ||
if host, ok := cfg.Hosts[args[0]]; ok { | ||
oldgroups := host.Groups | ||
host.Groups = groups | ||
cfg.Hosts[args[0]] = host | ||
cfg.Write() | ||
log.Printf("Groups for %s edited: %v\n", email, host.Groups) | ||
host.UpdateGroups(cfg, oldgroups) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsServerCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/shoobyban/sshman/backend" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// groupsUserCmd represents the user group editing command | ||
var groupsUserCmd = &cobra.Command{ | ||
Use: "user", | ||
Short: "Modify group assignments of a user", | ||
Long: `Modify user's groups, or remove groups from user to allow global access: | ||
$ ./sshman groups user [email protected] group1 group2 | ||
`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
cfg := backend.ReadConfig(backend.NewSFTP()) | ||
if len(args) < 1 { | ||
return | ||
} | ||
email := args[0] | ||
groups := args[1:] | ||
key, user := cfg.GetUserByEmail(email) | ||
if user != nil { | ||
oldgroups := user.Groups | ||
user.Groups = groups | ||
cfg.Users[key] = *user | ||
cfg.Write() | ||
log.Printf("Groups for %s edited: %v\n", email, groups) | ||
user.UpdateGroups(cfg, oldgroups) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
groupsCmd.AddCommand(groupsUserCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters