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

feat: commit signing using ssh and gpg #1146

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 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
17 changes: 17 additions & 0 deletions cmd/daytona/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ func GetDocsLinkFromGitProvider(providerId string) string {
}
}

func GetDocsLinkForCommitSigning(providerId string) string {
switch providerId {
case "github", "github-enterprise-server":
return "https://docs.github.com/en/authentication/managing-commit-signature-verification"
case "gitlab", "gitlab-self-managed":
return "https://docs.gitlab.com/ee/user/project/repository/signed_commits"
case "gitea":
return "https://docs.gitea.com/administration/signing"
case "azure-devops":
return "https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops"
case "aws-codecommit":
return "https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html"
default:
return ""
}
}

func GetRequiredScopesFromGitProviderId(providerId string) string {
switch providerId {
case "github":
Expand Down
4 changes: 2 additions & 2 deletions internal/testing/git/mocks/gitservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (m *MockGitService) RepositoryExists() (bool, error) {
return args.Bool(0), args.Error(1)
}

func (m *MockGitService) SetGitConfig(userData *gitprovider.GitUser) error {
args := m.Called(userData)
func (m *MockGitService) SetGitConfig(userData *gitprovider.GitUser, providerConfig *gitprovider.GitProviderConfig) error {
args := m.Called(userData, providerConfig)
return args.Error(0)
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ func (a *Agent) startProjectMode() error {
}
}

err = a.Git.SetGitConfig(gitUser)
var providerConfig *gitprovider.GitProviderConfig
if gitProvider != nil {
providerConfig = &gitprovider.GitProviderConfig{
SigningMethod: (*gitprovider.SigningMethod)(gitProvider.SigningMethod),
SigningKey: gitProvider.SigningKey,
}
}
err = a.Git.SetGitConfig(gitUser, providerConfig)
if err != nil {
log.Error(fmt.Sprintf("failed to set git config: %s", err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestAgent(t *testing.T) {

mockGitService := mock_git.NewMockGitService()
mockGitService.On("RepositoryExists").Return(true, nil)
mockGitService.On("SetGitConfig", mock.Anything).Return(nil)
mockGitService.On("SetGitConfig", mock.Anything, mock.Anything).Return(nil)
mockGitService.On("GetGitStatus").Return(gitStatus1, nil)

mockSshServer := mocks.NewMockSshServer()
Expand Down
14 changes: 10 additions & 4 deletions pkg/api/controllers/gitprovider/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

package dto

import (
"github.com/daytonaio/daytona/pkg/gitprovider"
)

type RepositoryUrl struct {
URL string `json:"url" validate:"required"`
} // @name RepositoryUrl

type SetGitProviderConfig struct {
Id string `json:"id" validate:"required"`
Username *string `json:"username" validate:"optional"`
Token string `json:"token" validate:"required"`
BaseApiUrl *string `json:"baseApiUrl,omitempty" validate:"optional"`
Id string `json:"id" validate:"required"`
Username *string `json:"username" validate:"optional"`
Token string `json:"token" validate:"required"`
BaseApiUrl *string `json:"baseApiUrl,omitempty" validate:"optional"`
SigningKey *string `json:"signingKey,omitempty" validate:"optional"`
SigningMethod *gitprovider.SigningMethod `json:"signingMethod,omitempty" validate:"optional"`
} // @name SetGitProviderConfig
9 changes: 6 additions & 3 deletions pkg/api/controllers/gitprovider/gitprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func ListGitProviders(ctx *gin.Context) {

for _, provider := range response {
provider.Token = ""
provider.SigningKey = nil
}

ctx.JSON(200, response)
Expand Down Expand Up @@ -132,9 +133,11 @@ func SetGitProvider(ctx *gin.Context) {
}

gitProviderConfig := gitprovider.GitProviderConfig{
Id: setConfigDto.Id,
Token: setConfigDto.Token,
BaseApiUrl: setConfigDto.BaseApiUrl,
Id: setConfigDto.Id,
Token: setConfigDto.Token,
BaseApiUrl: setConfigDto.BaseApiUrl,
SigningKey: setConfigDto.SigningKey,
SigningMethod: setConfigDto.SigningMethod,
}

if setConfigDto.Username != nil {
Expand Down
23 changes: 23 additions & 0 deletions pkg/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,12 @@ const docTemplate = `{
"id": {
"type": "string"
},
"signingKey": {
"type": "string"
},
"signingMethod": {
"$ref": "#/definitions/SigningMethod"
},
"token": {
"type": "string"
},
Expand Down Expand Up @@ -2689,6 +2695,12 @@ const docTemplate = `{
"id": {
"type": "string"
},
"signingKey": {
"type": "string"
},
"signingMethod": {
"$ref": "#/definitions/SigningMethod"
},
"token": {
"type": "string"
},
Expand All @@ -2711,6 +2723,17 @@ const docTemplate = `{
}
}
},
"SigningMethod": {
"type": "string",
"enum": [
"ssh",
"gpg"
],
"x-enum-varnames": [
"SigningMethodSSH",
"SigningMethodGPG"
]
},
"Status": {
"type": "string",
"enum": [
Expand Down
23 changes: 23 additions & 0 deletions pkg/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,12 @@
"id": {
"type": "string"
},
"signingKey": {
"type": "string"
},
"signingMethod": {
"$ref": "#/definitions/SigningMethod"
},
"token": {
"type": "string"
},
Expand Down Expand Up @@ -2686,6 +2692,12 @@
"id": {
"type": "string"
},
"signingKey": {
"type": "string"
},
"signingMethod": {
"$ref": "#/definitions/SigningMethod"
},
"token": {
"type": "string"
},
Expand All @@ -2708,6 +2720,17 @@
}
}
},
"SigningMethod": {
"type": "string",
"enum": [
"ssh",
"gpg"
],
"x-enum-varnames": [
"SigningMethodSSH",
"SigningMethodGPG"
]
},
"Status": {
"type": "string",
"enum": [
Expand Down
16 changes: 16 additions & 0 deletions pkg/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ definitions:
type: string
id:
type: string
signingKey:
type: string
signingMethod:
$ref: '#/definitions/SigningMethod'
token:
type: string
username:
Expand Down Expand Up @@ -652,6 +656,10 @@ definitions:
type: string
id:
type: string
signingKey:
type: string
signingMethod:
$ref: '#/definitions/SigningMethod'
token:
type: string
username:
Expand All @@ -669,6 +677,14 @@ definitions:
required:
- uptime
type: object
SigningMethod:
enum:
- ssh
- gpg
type: string
x-enum-varnames:
- SigningMethodSSH
- SigningMethodGPG
Status:
enum:
- Unmodified
Expand Down
1 change: 1 addition & 0 deletions pkg/apiclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Class | Method | HTTP request | Description
- [ServerConfig](docs/ServerConfig.md)
- [SetGitProviderConfig](docs/SetGitProviderConfig.md)
- [SetProjectState](docs/SetProjectState.md)
- [SigningMethod](docs/SigningMethod.md)
- [Status](docs/Status.md)
- [Workspace](docs/Workspace.md)
- [WorkspaceDTO](docs/WorkspaceDTO.md)
Expand Down
20 changes: 20 additions & 0 deletions pkg/apiclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1713,14 +1713,20 @@ components:
GitProvider:
example:
baseApiUrl: baseApiUrl
signingKey: signingKey
id: id
signingMethod: null
token: token
username: username
properties:
baseApiUrl:
type: string
id:
type: string
signingKey:
type: string
signingMethod:
$ref: '#/components/schemas/SigningMethod'
token:
type: string
username:
Expand Down Expand Up @@ -2280,14 +2286,20 @@ components:
SetGitProviderConfig:
example:
baseApiUrl: baseApiUrl
signingKey: signingKey
id: id
signingMethod: null
token: token
username: username
properties:
baseApiUrl:
type: string
id:
type: string
signingKey:
type: string
signingMethod:
$ref: '#/components/schemas/SigningMethod'
token:
type: string
username:
Expand Down Expand Up @@ -2321,6 +2333,14 @@ components:
required:
- uptime
type: object
SigningMethod:
enum:
- ssh
- gpg
type: string
x-enum-varnames:
- SigningMethodSSH
- SigningMethodGPG
Status:
enum:
- Unmodified
Expand Down
52 changes: 52 additions & 0 deletions pkg/apiclient/docs/GitProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**BaseApiUrl** | Pointer to **string** | | [optional]
**Id** | **string** | |
**SigningKey** | Pointer to **string** | | [optional]
**SigningMethod** | Pointer to [**SigningMethod**](SigningMethod.md) | | [optional]
**Token** | **string** | |
**Username** | **string** | |

Expand Down Expand Up @@ -73,6 +75,56 @@ and a boolean to check if the value has been set.
SetId sets Id field to given value.


### GetSigningKey

`func (o *GitProvider) GetSigningKey() string`

GetSigningKey returns the SigningKey field if non-nil, zero value otherwise.

### GetSigningKeyOk

`func (o *GitProvider) GetSigningKeyOk() (*string, bool)`

GetSigningKeyOk returns a tuple with the SigningKey field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetSigningKey

`func (o *GitProvider) SetSigningKey(v string)`

SetSigningKey sets SigningKey field to given value.

### HasSigningKey

`func (o *GitProvider) HasSigningKey() bool`

HasSigningKey returns a boolean if a field has been set.

### GetSigningMethod

`func (o *GitProvider) GetSigningMethod() SigningMethod`

GetSigningMethod returns the SigningMethod field if non-nil, zero value otherwise.

### GetSigningMethodOk

`func (o *GitProvider) GetSigningMethodOk() (*SigningMethod, bool)`

GetSigningMethodOk returns a tuple with the SigningMethod field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetSigningMethod

`func (o *GitProvider) SetSigningMethod(v SigningMethod)`

SetSigningMethod sets SigningMethod field to given value.

### HasSigningMethod

`func (o *GitProvider) HasSigningMethod() bool`

HasSigningMethod returns a boolean if a field has been set.

### GetToken

`func (o *GitProvider) GetToken() string`
Expand Down
Loading
Loading