-
Notifications
You must be signed in to change notification settings - Fork 14
Feature/332 kms key auth #363
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
Open
thijshberg
wants to merge
18
commits into
development
Choose a base branch
from
feature/332-kms-key-auth
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
18890eb
Add Key Management Store to the SSH capability
thijshberg 0a65bcf
Added example for the ssh KMS
thijshberg d1a8f3d
Added REST API for SSH key management
thijshberg ab82f18
Added key management unit tests
thijshberg ff98f14
Improve example deployment
thijshberg 5574c26
Added helper script for KMS example setup
thijshberg b3dbee3
Updated linting errors
thijshberg 7810776
Removed a public-private mixup
thijshberg 8c7a6c9
Removed lint error
thijshberg cb54807
Fixed the logger level configuration
thijshberg a0cec49
Changed KMS to use database backend
thijshberg b741642
Updated ssh-kms deployment and added ci
thijshberg 77eb7dd
Updated ci build to properly fetch keys
thijshberg 16ebe57
Smaller fixes from review
thijshberg efed787
Fixed name clash
thijshberg 2ea5e78
More capitalization errors
thijshberg 5b19a35
Fixing lint errors
thijshberg 589c193
Removed cached keys
thijshberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| FROM ubuntu:latest | ||
|
|
||
| RUN apt update && apt install openssh-server sudo -y | ||
|
|
||
| RUN sudo useradd -m sshtest | ||
|
|
||
| RUN ssh-keygen -q -N "" -f /test | ||
|
|
||
| RUN mkdir -p /home/sshtest/.ssh/ | ||
|
|
||
| RUN cat /test.pub > /home/sshtest/.ssh/authorized_keys | ||
|
|
||
| RUN echo "PasswordAuthentication no" >> /etc/ssh/sshd_config | ||
|
|
||
| RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config | ||
|
|
||
| RUN sudo service ssh start | ||
|
|
||
| EXPOSE 22 | ||
|
|
||
| CMD ["sudo","/usr/sbin/sshd","-D"] |
This file contains hidden or 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,8 @@ | ||
| services: | ||
| ssh_kms_server: | ||
| container_name: ssh_kms_server | ||
| build: | ||
| dockerfile: Dockerfile | ||
| ports: | ||
| - 2223:22 | ||
|
|
This file contains hidden or 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,117 @@ | ||
| { | ||
| "type": "playbook", | ||
| "spec_version": "cacao-2.0", | ||
| "id": "playbook--300270f9-0e64-42c8-93cc-0927edbe3ae7", | ||
| "name": "Example ssh", | ||
| "description": "This playbook demonstrates ssh functionality", | ||
| "playbook_types": [ | ||
| "notification" | ||
| ], | ||
| "created_by": "identity--96abab60-238a-44ff-8962-5806aa60cbce", | ||
| "created": "2023-11-20T15:56:00.123456Z", | ||
| "modified": "2023-11-20T15:56:00.123456Z", | ||
| "valid_from": "2023-11-20T15:56:00.123456Z", | ||
| "valid_until": "2123-11-20T15:56:00.123456Z", | ||
| "priority": 1, | ||
| "severity": 1, | ||
| "impact": 1, | ||
| "labels": [ | ||
| "soarca", | ||
| "ssh", | ||
| "example" | ||
| ], | ||
| "authentication_info_definitions": { | ||
| "user-auth--b7ddc2ea-9f6a-4e82-8eaa-be202e942090": { | ||
| "type": "user-auth", | ||
| "kms":true, | ||
| "kms_key_identifier": "test", | ||
| "username": "linuxserver.io" | ||
| } | ||
| }, | ||
| "agent_definitions": { | ||
| "soarca--00010001-1000-1000-a000-000100010001": { | ||
| "type": "soarca", | ||
| "name": "soarca-ssh" | ||
| } | ||
| }, | ||
| "target_definitions": { | ||
| "ssh--1c3900b4-f86b-430d-b415-12312b9e31f4": { | ||
| "type": "ssh", | ||
| "name": "system 1", | ||
| "address": { | ||
| "ipv4": [ | ||
| "127.0.0.1" | ||
| ] | ||
| }, | ||
| "port": "2223", | ||
| "authentication_info": "user-auth--b7ddc2ea-9f6a-4e82-8eaa-be202e942090" | ||
| } | ||
| }, | ||
| "external_references": [ | ||
| { | ||
| "name": "TNO COSSAS", | ||
| "description": "TNO COSSAS", | ||
| "source": "TNO COSSAS", | ||
| "url": "https://cossas-project.org" | ||
| } | ||
| ], | ||
| "workflow_start": "start--9e7d62b2-88ac-4656-94e1-dbd4413ba008", | ||
| "workflow_exception": "end--a6f0b81e-affb-4bca-b4f6-a2d5af908958", | ||
| "workflow": { | ||
| "start--9e7d62b2-88ac-4656-94e1-dbd4413ba008": { | ||
| "type": "start", | ||
| "name": "Start ssh example", | ||
| "on_completion": "action--eb9372d4-d524-49fc-bf24-be26ea084779" | ||
| }, | ||
| "action--eb9372d4-d524-49fc-bf24-be26ea084779": { | ||
| "type": "action", | ||
| "name": "Execute command", | ||
| "description": "Execute command specified in variable", | ||
| "on_completion": "action--88f4c4df-fa96-44e6-b310-1c06d193ea55", | ||
| "commands": [ | ||
| { | ||
| "type": "ssh", | ||
| "command": "__command__:value" | ||
| } | ||
| ], | ||
| "targets": [ | ||
| "ssh--1c3900b4-f86b-430d-b415-12312b9e31f4" | ||
| ], | ||
| "agent": "soarca--00010001-1000-1000-a000-000100010001", | ||
| "step_variables": { | ||
| "__command__": { | ||
| "type": "string", | ||
| "value": "ls -la", | ||
| "constant": true | ||
| } | ||
| } | ||
| }, | ||
| "action--88f4c4df-fa96-44e6-b310-1c06d193ea55": { | ||
| "type": "action", | ||
| "name": "Touch file", | ||
| "description": "Touch file at path specified by variable", | ||
| "on_completion": "end--a6f0b81e-affb-4bca-b4f6-a2d5af908958", | ||
| "commands": [ | ||
| { | ||
| "type": "ssh", | ||
| "command": "touch __path__:value" | ||
| } | ||
| ], | ||
| "targets": [ | ||
| "ssh--1c3900b4-f86b-430d-b415-12312b9e31f4" | ||
| ], | ||
| "agent": "soarca--00010001-1000-1000-a000-000100010001", | ||
| "step_variables": { | ||
| "__path__": { | ||
| "type": "string", | ||
| "value": "touchy", | ||
| "constant": true | ||
| } | ||
| } | ||
| }, | ||
| "end--a6f0b81e-affb-4bca-b4f6-a2d5af908958": { | ||
| "type": "end", | ||
| "name": "End Flow" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,69 @@ | ||
| package keymanagementrepository | ||
|
|
||
| import ( | ||
| "errors" | ||
| "soarca/internal/database" | ||
| "soarca/pkg/models/keymanagement" | ||
| ) | ||
|
|
||
| type IKeyManagementRepository interface { | ||
| GetKeyNames() ([]string, error) | ||
| Create(name string, keypair keymanagement.KeyPair) error | ||
| Read(id string) (keymanagement.KeyPair, error) | ||
| Update(id string, keypair keymanagement.KeyPair) error | ||
| Delete(id string) error | ||
| } | ||
|
|
||
| type KeyManagementRepository struct { | ||
| db database.Database | ||
| options database.FindOptions | ||
| } | ||
|
|
||
| type KeyPairEntry struct { | ||
| name string | ||
| keypair keymanagement.KeyPair | ||
| } | ||
|
|
||
| func SetupKeyManagementRepository(db database.Database, options database.FindOptions) *KeyManagementRepository { | ||
| return &KeyManagementRepository{db: db, options: options} | ||
| } | ||
|
|
||
| func (keymanagementRepo *KeyManagementRepository) GetKeyNames() ([]string, error) { | ||
| keys, err := keymanagementRepo.db.Find(nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| ret := []string{} | ||
| for _, key := range keys { | ||
| ret = append(ret, key.(KeyPairEntry).name) | ||
| } | ||
| return ret, nil | ||
| } | ||
|
|
||
| func (keymanagementRepo *KeyManagementRepository) Create(name string, keypair keymanagement.KeyPair) error { | ||
| return keymanagementRepo.db.Create(KeyPairEntry{name, keypair}) | ||
| } | ||
|
|
||
| func (keymanagementRepo *KeyManagementRepository) Read(id string) (keymanagement.KeyPair, error) { | ||
| returnedObject, err := keymanagementRepo.db.Read(id) | ||
| if err != nil { | ||
| return keymanagement.KeyPair{}, err | ||
| } | ||
|
|
||
| keypair, ok := returnedObject.(keymanagement.KeyPair) | ||
|
|
||
| if !ok { | ||
| err = errors.New("could not cast lookup object to keypair type") | ||
| return keymanagement.KeyPair{}, err | ||
| } | ||
|
|
||
| return keypair, nil | ||
| } | ||
|
|
||
| func (keymanagementRepo *KeyManagementRepository) Update(id string, keypair keymanagement.KeyPair) error { | ||
| return keymanagementRepo.db.Update(id, keypair) | ||
| } | ||
|
|
||
| func (keymanagementRepo *KeyManagementRepository) Delete(id string) error { | ||
| return keymanagementRepo.db.Delete(id) | ||
| } |
This file contains hidden or 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,41 @@ | ||
| package memory | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "soarca/pkg/models/keymanagement" | ||
| ) | ||
|
|
||
| type InMemoryKeyManagementDatabase struct { | ||
| keys map[string]keymanagement.KeyPair | ||
| } | ||
|
|
||
| func NewKeyManagementDatabase() *InMemoryKeyManagementDatabase { | ||
| return &InMemoryKeyManagementDatabase{keys: make(map[string]keymanagement.KeyPair)} | ||
| } | ||
|
|
||
| func (database *InMemoryKeyManagementDatabase) GetKeyNames() ([]string, error) { | ||
| ret := []string{} | ||
| for key := range database.keys { | ||
| ret = append(ret, key) | ||
| } | ||
| return ret, nil | ||
| } | ||
| func (database *InMemoryKeyManagementDatabase) Create(name string, keypair keymanagement.KeyPair) error { | ||
| database.keys[name] = keypair | ||
| return nil | ||
| } | ||
| func (database *InMemoryKeyManagementDatabase) Read(id string) (keymanagement.KeyPair, error) { | ||
| keypair, ok := database.keys[id] | ||
| if !ok { | ||
| return keymanagement.KeyPair{}, fmt.Errorf("could not find key named %s", id) | ||
| } | ||
| return keypair, nil | ||
| } | ||
| func (database *InMemoryKeyManagementDatabase) Update(id string, keypair keymanagement.KeyPair) error { | ||
| database.keys[id] = keypair | ||
| return nil | ||
| } | ||
| func (database *InMemoryKeyManagementDatabase) Delete(id string) error { | ||
| delete(database.keys, id) | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.