Skip to content

Commit 97c20c0

Browse files
rizul2108Althaf66Vad1mo
authored
feat: Add systemcve cli cmd (goharbor#388)
* created systemcve cmd Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * modified systemcve cmd Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * modified to harbor cve-allowlist list/add Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * Update cmd.go Signed-off-by: ALTHAF <114910365+Althaf66@users.noreply.github.com> * fix lint issue Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * changed date to iso format Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * modified cveallowlist cmd Signed-off-by: ALTHAF <althafasharaf02@gmail.com> * add docs Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * fix lint issues Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * fix lint issues Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> fixes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> fixes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * header fixes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * suggested changes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * small changes Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> * lint fix Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> --------- Signed-off-by: ALTHAF <althafasharaf02@gmail.com> Signed-off-by: ALTHAF <114910365+Althaf66@users.noreply.github.com> Signed-off-by: Rizul Gupta <mail2rizul@gmail.com> Signed-off-by: Vadim Bauer <vb@container-registry.com> Co-authored-by: ALTHAF <althafasharaf02@gmail.com> Co-authored-by: ALTHAF <114910365+Althaf66@users.noreply.github.com> Co-authored-by: Vadim Bauer <vb@container-registry.com>
1 parent 7fa59cd commit 97c20c0

13 files changed

Lines changed: 583 additions & 2 deletions

File tree

cmd/harbor/root/cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919

2020
"github.com/goharbor/harbor-cli/cmd/harbor/root/artifact"
2121
"github.com/goharbor/harbor-cli/cmd/harbor/root/config"
22+
"github.com/goharbor/harbor-cli/cmd/harbor/root/cve"
2223
"github.com/goharbor/harbor-cli/cmd/harbor/root/instance"
2324
"github.com/goharbor/harbor-cli/cmd/harbor/root/labels"
2425
"github.com/goharbor/harbor-cli/cmd/harbor/root/project"
2526
"github.com/goharbor/harbor-cli/cmd/harbor/root/registry"
26-
repositry "github.com/goharbor/harbor-cli/cmd/harbor/root/repository"
27+
"github.com/goharbor/harbor-cli/cmd/harbor/root/repository"
2728
"github.com/goharbor/harbor-cli/cmd/harbor/root/schedule"
2829
"github.com/goharbor/harbor-cli/cmd/harbor/root/tag"
2930
"github.com/goharbor/harbor-cli/cmd/harbor/root/user"
@@ -95,11 +96,12 @@ harbor help
9596
config.Config(),
9697
project.Project(),
9798
registry.Registry(),
98-
repositry.Repository(),
99+
repository.Repository(),
99100
user.User(),
100101
artifact.Artifact(),
101102
tag.TagCommand(),
102103
HealthCommand(),
104+
cve.CVEAllowlist(),
103105
schedule.Schedule(),
104106
labels.Labels(),
105107
InfoCommand(),

cmd/harbor/root/cve/add.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package cve
15+
16+
import (
17+
"github.com/goharbor/harbor-cli/pkg/api"
18+
"github.com/goharbor/harbor-cli/pkg/views/cveallowlist/update"
19+
log "github.com/sirupsen/logrus"
20+
"github.com/spf13/cobra"
21+
)
22+
23+
func AddCveAllowlistCommand() *cobra.Command {
24+
var opts update.UpdateView
25+
26+
cmd := &cobra.Command{
27+
Use: "add",
28+
Short: "Add cve allowlist",
29+
Long: "Create allowlist of CVEs to ignore during vulnerability scanning",
30+
Run: func(cmd *cobra.Command, args []string) {
31+
var err error
32+
updateView := &update.UpdateView{
33+
CveId: opts.CveId,
34+
IsExpire: opts.IsExpire,
35+
ExpireDate: opts.ExpireDate,
36+
}
37+
38+
err = updatecveView(updateView)
39+
if err != nil {
40+
log.Errorf("failed to add cveallowlist: %v", err)
41+
}
42+
},
43+
}
44+
45+
flags := cmd.Flags()
46+
flags.BoolVarP(&opts.IsExpire, "isexpire", "i", false, "Indicates whether the CVE entries should have an expiration date. Set to true to specify an expiration date")
47+
flags.StringVarP(&opts.CveId, "cveid", "n", "", "Comma-separated list of CVE IDs to be added to the allowlist")
48+
flags.StringVarP(&opts.ExpireDate, "expiredate", "d", "", "Specifies the expiration date for the CVE entries in the format 'YYYY-MM-DD'")
49+
50+
return cmd
51+
}
52+
53+
func updatecveView(updateView *update.UpdateView) error {
54+
if updateView == nil {
55+
updateView = &update.UpdateView{}
56+
}
57+
58+
update.UpdateCveView(updateView)
59+
return api.UpdateSystemCve(*updateView)
60+
}

cmd/harbor/root/cve/cmd.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package cve
15+
16+
import (
17+
"github.com/spf13/cobra"
18+
)
19+
20+
func CVEAllowlist() *cobra.Command {
21+
cmd := &cobra.Command{
22+
Use: "cve-allowlist",
23+
Short: "Manage system CVE allowlist",
24+
Long: `Managing CVE lists that are intentionally excluded from vulnerability scanning`,
25+
Example: `harbor cve-allowlist list`,
26+
}
27+
cmd.AddCommand(
28+
ListCveCommand(),
29+
AddCveAllowlistCommand(),
30+
)
31+
32+
return cmd
33+
}

cmd/harbor/root/cve/list.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright Project Harbor Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package cve
15+
16+
import (
17+
"github.com/goharbor/harbor-cli/pkg/api"
18+
"github.com/goharbor/harbor-cli/pkg/utils"
19+
"github.com/goharbor/harbor-cli/pkg/views/cveallowlist/list"
20+
log "github.com/sirupsen/logrus"
21+
"github.com/spf13/cobra"
22+
"github.com/spf13/viper"
23+
)
24+
25+
func ListCveCommand() *cobra.Command {
26+
cmd := &cobra.Command{
27+
Use: "list",
28+
Short: "List system level allowlist of cve",
29+
Args: cobra.NoArgs,
30+
Run: func(cmd *cobra.Command, args []string) {
31+
cve, err := api.ListSystemCve()
32+
if err != nil {
33+
log.Fatalf("failed to get system cve list: %v", err)
34+
}
35+
FormatFlag := viper.GetString("output-format")
36+
if FormatFlag != "" {
37+
err = utils.PrintFormat(cve, FormatFlag)
38+
if err != nil {
39+
log.Fatalf("failed to print cve list: %v", err)
40+
return
41+
}
42+
} else {
43+
list.ListSystemCve(cve.Payload)
44+
}
45+
},
46+
}
47+
48+
return cmd
49+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: harbor cve allowlist add
3+
weight: 60
4+
---
5+
## harbor cve-allowlist add
6+
7+
### Description
8+
9+
##### Add cve allowlist
10+
11+
### Synopsis
12+
13+
Create allowlists of CVEs to ignore during vulnerability scanning
14+
15+
```sh
16+
harbor cve-allowlist add [flags]
17+
```
18+
19+
### Options
20+
21+
```sh
22+
-n, --cveid string Comma-separated list of CVE IDs to be added to the allowlist
23+
-d, --expiredate string Specifies the expiration date for the CVE entries in the format 'YYYY-MM-DD'
24+
-h, --help help for add
25+
-i, --isexpire Indicates whether the CVE entries should have an expiration date. Set to true to specify an expiration date
26+
```
27+
28+
### Options inherited from parent commands
29+
30+
```sh
31+
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
32+
-o, --output-format string Output format. One of: json|yaml
33+
-v, --verbose verbose output
34+
```
35+
36+
### SEE ALSO
37+
38+
* [harbor cve-allowlist](harbor-cve-allowlist.md) - Manage system CVE allowlist
39+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: harbor cve allowlist list
3+
weight: 60
4+
---
5+
## harbor cve-allowlist list
6+
7+
### Description
8+
9+
##### list system level allowlist of cve
10+
11+
```sh
12+
harbor cve-allowlist list [flags]
13+
```
14+
15+
### Options
16+
17+
```sh
18+
-h, --help help for list
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```sh
24+
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
25+
-o, --output-format string Output format. One of: json|yaml
26+
-v, --verbose verbose output
27+
```
28+
29+
### SEE ALSO
30+
31+
* [harbor cve-allowlist](harbor-cve-allowlist.md) - Manage system CVE allowlist
32+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: harbor cve allowlist
3+
weight: 70
4+
---
5+
## harbor cve-allowlist
6+
7+
### Description
8+
9+
##### Manage system CVE allowlist
10+
11+
### Synopsis
12+
13+
Managing CVE lists that are intentionally excluded from vulnerability scanning
14+
15+
### Examples
16+
17+
```sh
18+
harbor cve-allowlist list
19+
```
20+
21+
### Options
22+
23+
```sh
24+
-h, --help help for cve-allowlist
25+
```
26+
27+
### Options inherited from parent commands
28+
29+
```sh
30+
-c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml)
31+
-o, --output-format string Output format. One of: json|yaml
32+
-v, --verbose verbose output
33+
```
34+
35+
### SEE ALSO
36+
37+
* [harbor](harbor.md) - Official Harbor CLI
38+
* [harbor cve-allowlist add](harbor-cve-allowlist-add.md) - Add cve allowlist
39+
* [harbor cve-allowlist list](harbor-cve-allowlist-list.md) - list system level allowlist of cve
40+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.nh
2+
.TH "HARBOR" "1" "Habor Community" "Harbor User Mannuals"
3+
4+
.SH NAME
5+
harbor-cve-allowlist-add - Add cve allowlist
6+
7+
8+
.SH SYNOPSIS
9+
\fBharbor cve-allowlist add [flags]\fP
10+
11+
12+
.SH DESCRIPTION
13+
Create allowlists of CVEs to ignore during vulnerability scanning
14+
15+
16+
.SH OPTIONS
17+
\fB-n\fP, \fB--cveid\fP=""
18+
Comma-separated list of CVE IDs to be added to the allowlist
19+
20+
.PP
21+
\fB-d\fP, \fB--expiredate\fP=""
22+
Specifies the expiration date for the CVE entries in the format 'YYYY-MM-DD'
23+
24+
.PP
25+
\fB-h\fP, \fB--help\fP[=false]
26+
help for add
27+
28+
.PP
29+
\fB-i\fP, \fB--isexpire\fP[=false]
30+
Indicates whether the CVE entries should have an expiration date. Set to true to specify an expiration date
31+
32+
33+
.SH OPTIONS INHERITED FROM PARENT COMMANDS
34+
\fB-c\fP, \fB--config\fP=""
35+
config file (default is $HOME/.config/harbor-cli/config.yaml)
36+
37+
.PP
38+
\fB-o\fP, \fB--output-format\fP=""
39+
Output format. One of: json|yaml
40+
41+
.PP
42+
\fB-v\fP, \fB--verbose\fP[=false]
43+
verbose output
44+
45+
46+
.SH SEE ALSO
47+
\fBharbor-cve-allowlist(1)\fP
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.nh
2+
.TH "HARBOR" "1" "Habor Community" "Harbor User Mannuals"
3+
4+
.SH NAME
5+
harbor-cve-allowlist-list - list system level allowlist of cve
6+
7+
8+
.SH SYNOPSIS
9+
\fBharbor cve-allowlist list [flags]\fP
10+
11+
12+
.SH DESCRIPTION
13+
list system level allowlist of cve
14+
15+
16+
.SH OPTIONS
17+
\fB-h\fP, \fB--help\fP[=false]
18+
help for list
19+
20+
21+
.SH OPTIONS INHERITED FROM PARENT COMMANDS
22+
\fB-c\fP, \fB--config\fP=""
23+
config file (default is $HOME/.config/harbor-cli/config.yaml)
24+
25+
.PP
26+
\fB-o\fP, \fB--output-format\fP=""
27+
Output format. One of: json|yaml
28+
29+
.PP
30+
\fB-v\fP, \fB--verbose\fP[=false]
31+
verbose output
32+
33+
34+
.SH SEE ALSO
35+
\fBharbor-cve-allowlist(1)\fP

0 commit comments

Comments
 (0)