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

Merged
merged 50 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b00db8b
feat: add support for commit signing
divanshu-go Oct 1, 2024
a65318e
hide signing key and show signing method
divanshu-go Oct 1, 2024
a442f1e
hide signing key and show signing method
divanshu-go Oct 1, 2024
c1bd88c
fix
divanshu-go Oct 1, 2024
c0079d6
fix
divanshu-go Oct 1, 2024
09e4eed
fix
divanshu-go Jan 5, 2024
c5043ba
verify ssh commits locally
divanshu-go Oct 3, 2024
1dddf9a
fix
divanshu-go Oct 3, 2024
b4aca6a
please test changes
divanshu-go Oct 4, 2024
9997aee
Merge branch 'main' into commits-git
divanshu-go Oct 4, 2024
9b3b721
fix
divanshu-go Oct 4, 2024
96a8f04
fix
divanshu-go Oct 4, 2024
e7cabe7
fix
divanshu-go Oct 5, 2024
a552ba4
refactor and add gpg setup functions
divanshu-go Oct 5, 2024
d95c622
fix
divanshu-go Oct 6, 2024
d039fbc
fix
divanshu-go Oct 6, 2024
c812e7f
refactor code and add mask bool to gp
divanshu-go Oct 7, 2024
c95e12f
fix
divanshu-go Oct 7, 2024
ed7f4ca
fix
divanshu-go Oct 7, 2024
b5829e7
refactor code
divanshu-go Oct 7, 2024
a28a422
fix
divanshu-go Oct 8, 2024
30acc35
refactor and check if gpg is installed
divanshu-go Oct 8, 2024
3018bf1
remove duplicate function
divanshu-go Oct 8, 2024
944a1d7
Merge branch 'daytonaio:main' into commits-git
divanshu-go Oct 8, 2024
87915fc
fix
divanshu-go Oct 8, 2024
1dbbec7
fix
divanshu-go Oct 9, 2024
aaf817b
fix
divanshu-go Oct 9, 2024
8858598
fix done
divanshu-go Oct 9, 2024
9bfbe6d
resolve merge conflicts
divanshu-go Oct 10, 2024
8f3b150
resolve issues
divanshu-go Oct 10, 2024
198c597
fix lint
divanshu-go Oct 10, 2024
1667dd6
Merge branch 'main' into commits-git
divanshu-go Oct 11, 2024
b23418d
fix
divanshu-go Oct 11, 2024
f3eb4c1
Merge branch 'main' into commits-git
divanshu-go Oct 11, 2024
b5c4bcd
lint
divanshu-go Oct 11, 2024
a722b33
lint
divanshu-go Oct 11, 2024
921366b
merge conflict resolved
divanshu-go Oct 11, 2024
b2419ff
refactor code
divanshu-go Oct 11, 2024
c41ba7a
resolve and refactor merge conflicts
divanshu-go Oct 11, 2024
d6d8314
refactor and update git api methods
divanshu-go Oct 12, 2024
7760bd3
fix lint
divanshu-go Oct 13, 2024
89a3434
fix
divanshu-go Oct 13, 2024
a2b699d
remove nil checks
divanshu-go Oct 14, 2024
1a3488f
fix
divanshu-go Oct 14, 2024
68ed24b
fix
divanshu-go Oct 14, 2024
3cb4924
lint
divanshu-go Oct 14, 2024
daa9f3e
fix
divanshu-go Oct 14, 2024
5258778
resolve conflicts
divanshu-go Oct 15, 2024
cad2122
add field signing method
divanshu-go Oct 15, 2024
0a09a10
use trace instead of warn
divanshu-go Oct 16, 2024
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