-
Notifications
You must be signed in to change notification settings - Fork 547
fix: image scanning flows #6213
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3889783
resource scan dev
Shivam-nagar23 90ca477
image scanning
Shivam-nagar23 ce7e4f7
review comments
Shivam-nagar23 e2d6e79
refactoring
Shivam-nagar23 1fa3f8c
is imageScanned enabled
Shivam-nagar23 7017555
Merge branch 'develop' into fix-image-scan-flow
Shivam-nagar23 5a65f44
review comments resolved
Shivam-nagar23 14cb5be
remove scanevent struct and replace with common lib struct
prakash100198 c4a76ec
Merge branch 'develop' into fix-image-scan-flow
Shivam-nagar23 3fa6151
Merge branch 'develop' into fix-image-scan-flow
prakash100198 35fe5eb
oss app details
Shivam-nagar23 e9d69d3
Merge branch 'develop' into fix-image-scan-flow
prakash100198 59958e0
scanned check fix
prakash100198 9e8cb8d
revert
prakash100198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (c) 2024. Devtron Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package resourceScan | ||
|
||
import ( | ||
"fmt" | ||
"github.com/devtron-labs/devtron/api/restHandler/common" | ||
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" | ||
"github.com/devtron-labs/devtron/pkg/auth/user" | ||
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning" | ||
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/bean" | ||
"github.com/devtron-labs/devtron/util/rbac" | ||
"go.uber.org/zap" | ||
"gopkg.in/go-playground/validator.v9" | ||
"net/http" | ||
) | ||
|
||
type ScanningResultRestHandler interface { | ||
ScanResults(w http.ResponseWriter, r *http.Request) | ||
} | ||
|
||
type ScanningResultRestHandlerImpl struct { | ||
logger *zap.SugaredLogger | ||
userService user.UserService | ||
scanService imageScanning.ImageScanService | ||
enforcer casbin.Enforcer | ||
enforcerUtil rbac.EnforcerUtil | ||
validator *validator.Validate | ||
} | ||
|
||
func NewScanningResultRestHandlerImpl( | ||
logger *zap.SugaredLogger, | ||
userService user.UserService, | ||
scanService imageScanning.ImageScanService, | ||
enforcer casbin.Enforcer, | ||
enforcerUtil rbac.EnforcerUtil, | ||
validator *validator.Validate, | ||
) *ScanningResultRestHandlerImpl { | ||
return &ScanningResultRestHandlerImpl{ | ||
logger: logger, | ||
userService: userService, | ||
scanService: scanService, | ||
enforcer: enforcer, | ||
enforcerUtil: enforcerUtil, | ||
validator: validator, | ||
} | ||
} | ||
|
||
func getResourceScanQueryParams(w http.ResponseWriter, r *http.Request) (*bean.ResourceScanQueryParams, error) { | ||
queryParams := &bean.ResourceScanQueryParams{} | ||
var appId, envId, installedAppId, artifactId, installedAppVersionHistoryId int | ||
var err error | ||
appId, err = common.ExtractIntQueryParam(w, r, "appId", 0) | ||
if err != nil { | ||
return queryParams, err | ||
} | ||
queryParams.AppId = appId | ||
|
||
installedAppId, err = common.ExtractIntQueryParam(w, r, "installedAppId", 0) | ||
if err != nil { | ||
return queryParams, err | ||
} | ||
queryParams.InstalledAppId = installedAppId | ||
|
||
installedAppVersionHistoryId, err = common.ExtractIntQueryParam(w, r, "installedAppVersionHistoryId", 0) | ||
if err != nil { | ||
return queryParams, err | ||
} | ||
queryParams.InstalledAppVersionHistoryId = installedAppVersionHistoryId | ||
|
||
envId, err = common.ExtractIntQueryParam(w, r, "envId", 0) | ||
if err != nil { | ||
return queryParams, err | ||
} | ||
queryParams.EnvId = envId | ||
|
||
artifactId, err = common.ExtractIntQueryParam(w, r, "artifactId", 0) | ||
if err != nil { | ||
return queryParams, err | ||
} | ||
queryParams.ArtifactId = artifactId | ||
return queryParams, nil | ||
} | ||
|
||
func (impl ScanningResultRestHandlerImpl) ScanResults(w http.ResponseWriter, r *http.Request) { | ||
userId, err := impl.userService.GetLoggedInUser(r) | ||
if userId == 0 || err != nil { | ||
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized) | ||
return | ||
} | ||
resourceScanQueryParams, err := getResourceScanQueryParams(w, r) | ||
if err != nil { | ||
return | ||
} | ||
// RBAC | ||
token := r.Header.Get("token") | ||
object := impl.enforcerUtil.GetAppRBACNameByAppId(resourceScanQueryParams.AppId) | ||
if ok := impl.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok { | ||
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden) | ||
return | ||
} | ||
if resourceScanQueryParams.EnvId > 0 { | ||
object = impl.enforcerUtil.GetEnvRBACNameByAppId(resourceScanQueryParams.AppId, resourceScanQueryParams.EnvId) | ||
if ok := impl.enforcer.Enforce(token, casbin.ResourceEnvironment, casbin.ActionGet, object); !ok { | ||
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden) | ||
return | ||
} | ||
} | ||
// RBAC | ||
resp, err := impl.scanService.GetScanResults(resourceScanQueryParams) | ||
if err != nil { | ||
impl.logger.Errorw("service err, GetScanResults", "resourceScanQueryParams", resourceScanQueryParams, "err", err) | ||
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
common.WriteJsonResp(w, nil, resp, http.StatusOK) | ||
|
||
} |
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,25 @@ | ||
/* | ||
* Copyright (c) 2024. Devtron Inc. | ||
*/ | ||
|
||
package resourceScan | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
type ScanningResultRouter interface { | ||
InitScanningResultRouter(configRouter *mux.Router) | ||
} | ||
|
||
type ScanningResultRouterImpl struct { | ||
ScanningResultRestHandler ScanningResultRestHandler | ||
} | ||
|
||
func NewScanningResultRouterImpl(ScanningResultRestHandler ScanningResultRestHandler) *ScanningResultRouterImpl { | ||
return &ScanningResultRouterImpl{ScanningResultRestHandler: ScanningResultRestHandler} | ||
} | ||
|
||
func (router *ScanningResultRouterImpl) InitScanningResultRouter(configRouter *mux.Router) { | ||
configRouter.Path("").HandlerFunc(router.ScanningResultRestHandler.ScanResults).Methods("GET") | ||
} |
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,16 @@ | ||
/* | ||
* Copyright (c) 2024. Devtron Inc. | ||
*/ | ||
|
||
package resourceScan | ||
|
||
import ( | ||
"github.com/google/wire" | ||
) | ||
|
||
var ScanningResultWireSet = wire.NewSet( | ||
NewScanningResultRouterImpl, | ||
wire.Bind(new(ScanningResultRouter), new(*ScanningResultRouterImpl)), | ||
NewScanningResultRestHandlerImpl, | ||
wire.Bind(new(ScanningResultRestHandler), new(*ScanningResultRestHandlerImpl)), | ||
) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
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.