From a77927c9f2ee35e8dad8335e7c4e55d108259562 Mon Sep 17 00:00:00 2001 From: nirav-rafay <93963752+nirav-rafay@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:56:35 +0530 Subject: [PATCH 1/5] Create codeql.yml --- .github/workflows/codeql.yml | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..8ae5d04 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main", *main* ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '30 16 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 From 5cd15cbd8e3a72c46618bec6b351f215b2873cc6 Mon Sep 17 00:00:00 2001 From: Nirav Parikh Date: Mon, 27 Jun 2022 12:02:15 +0530 Subject: [PATCH 2/5] fixed action criteria --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8ae5d04..5ba66a4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,7 +13,7 @@ name: "CodeQL" on: push: - branches: [ "main", *main* ] + branches: [ "main", "*main*" ] pull_request: # The branches below must be a subset of the branches above branches: [ "main" ] From 58e83c42a3b954496b486c26891f7ad7f8cb658a Mon Sep 17 00:00:00 2001 From: Nirav Parikh Date: Mon, 27 Jun 2022 13:13:44 +0530 Subject: [PATCH 3/5] removed scheduling from codeql and fixed an alert --- .github/workflows/codeql.yml | 2 -- pkg/service/cluster.go | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5ba66a4..39a3c48 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -17,8 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ "main" ] - schedule: - - cron: '30 16 * * 0' jobs: analyze: diff --git a/pkg/service/cluster.go b/pkg/service/cluster.go index eaf31f9..74e8c87 100644 --- a/pkg/service/cluster.go +++ b/pkg/service/cluster.go @@ -418,7 +418,11 @@ func (s *clusterService) prepareClusterResponse(ctx context.Context, clstr *infr ModifiedAt: timestamppb.New(c.ModifiedAt), } - sm, _ := strconv.Atoi(c.ShareMode) + smv, _ := strconv.ParseInt(c.ShareMode, 10, 32) + if err != nil { + _log.Infow("unable to convert value, ", err.Error()) + } + sm := int32(smv) var proxy infrav3.ProxyConfig if c.ProxyConfig != nil { json.Unmarshal(c.ProxyConfig, &proxy) From d6d0184878503983d6842e1a572cee0e768a6d70 Mon Sep 17 00:00:00 2001 From: Nirav Parikh Date: Mon, 27 Jun 2022 15:32:27 +0530 Subject: [PATCH 4/5] fixing codeql alerts --- pkg/sentry/register/register.go | 2 +- pkg/sentry/util/addr.go | 7 +++++-- pkg/service/cluster.go | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/sentry/register/register.go b/pkg/sentry/register/register.go index 4fc7f30..de3323e 100644 --- a/pkg/sentry/register/register.go +++ b/pkg/sentry/register/register.go @@ -92,7 +92,7 @@ type Config struct { // ServerPort is port the registered server should listen on // it is returned after registration - ServerPort int + ServerPort int32 } func registerHTTP(ctx context.Context, config *Config) error { diff --git a/pkg/sentry/util/addr.go b/pkg/sentry/util/addr.go index e14d377..e1a78d6 100644 --- a/pkg/sentry/util/addr.go +++ b/pkg/sentry/util/addr.go @@ -1,17 +1,20 @@ package util import ( + "math" "strconv" "strings" ) // ParseAddr parses addr into host and port -func ParseAddr(addr string) (host string, port int) { +func ParseAddr(addr string) (host string, port int32) { idx := strings.Index(addr, ":") if idx >= 0 { host = addr[0:idx] p, _ := strconv.ParseInt(addr[idx+1:], 10, 64) - port = int(p) + if p > 0 && p <= math.MaxInt32 { + port = int32(p) + } } return } diff --git a/pkg/service/cluster.go b/pkg/service/cluster.go index 74e8c87..68f85ca 100644 --- a/pkg/service/cluster.go +++ b/pkg/service/cluster.go @@ -418,11 +418,13 @@ func (s *clusterService) prepareClusterResponse(ctx context.Context, clstr *infr ModifiedAt: timestamppb.New(c.ModifiedAt), } - smv, _ := strconv.ParseInt(c.ShareMode, 10, 32) + sm := int32(infrav3.ClusterShareMode_ClusterShareModeNotSet) + smv, err := strconv.ParseInt(c.ShareMode, 10, 32) if err != nil { _log.Infow("unable to convert value, ", err.Error()) + } else { + sm = int32(smv) } - sm := int32(smv) var proxy infrav3.ProxyConfig if c.ProxyConfig != nil { json.Unmarshal(c.ProxyConfig, &proxy) From 0177911be70c73c1dd7182c15d28fcf3e6602b5a Mon Sep 17 00:00:00 2001 From: Nirav Parikh Date: Mon, 27 Jun 2022 16:57:53 +0530 Subject: [PATCH 5/5] updated codeql wf strategy --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 39a3c48..0c48681 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,7 +13,7 @@ name: "CodeQL" on: push: - branches: [ "main", "*main*" ] + branches: [ "main" ] pull_request: # The branches below must be a subset of the branches above branches: [ "main" ]