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

[TT-11953] go 1 22 upgrade #6269

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Conversation

andrei-tyk
Copy link
Contributor

@andrei-tyk andrei-tyk commented May 13, 2024

User description

Description

This is a test PR to check why some CI pipelines are failing on a different PR.

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

enhancement, documentation


Description

  • Added a function setGODEBUG in gateway/server.go to set the GODEBUG environment variable for enabling deprecated ciphers, ensuring compatibility with Go 1.22.
  • Included unit tests for the new setGODEBUG function in gateway/server_test.go.
  • Updated Go version to 1.22 across various configuration files including GitHub Actions workflows, Dockerfile, go.mod, and Taskfile.yml.
  • Updated documentation in README.md to reflect the new Go version requirement.

Changes walkthrough 📝

Relevant files
Enhancement
server.go
Add function to set GODEBUG for deprecated ciphers compatibility

gateway/server.go

  • Added a new function setGODEBUG to set the GODEBUG environment
    variable to enable deprecated ciphers for compatibility with Go 1.22.
  • Called setGODEBUG in the Start function to ensure it is set at
    runtime.
  • +19/-0   
    Tests
    server_test.go
    Unit tests for setGODEBUG function                                             

    gateway/server_test.go

  • Added tests for the new setGODEBUG function to ensure it correctly
    sets the environment variable.
  • +18/-0   
    Configuration changes
    *.yml
    Update GitHub Actions workflows to Go 1.22                             

    .github/workflows/*.yml

  • Updated Go version to 1.22 in various GitHub Actions workflows to
    ensure compatibility with the new Go version.
  • Dockerfile
    Update Dockerfile to use Go 1.22                                                 

    Dockerfile

  • Updated the Go version in Dockerfile to 1.22 to match the project's Go
    version upgrade.
  • +2/-2     
    go.mod
    Update go.mod to specify Go 1.22                                                 

    go.mod

  • Updated the Go version in go.mod to 1.22 to align with the latest Go
    standards.
  • +1/-3     
    Taskfile.yml
    Update Taskfile.yml to use Go 1.22                                             

    Taskfile.yml

  • Updated Go version in Taskfile.yml to ensure the build scripts use the
    correct Go version.
  • +2/-2     
    Documentation
    README.md
    Update README with new Go version requirement                       

    README.md

  • Updated the required Go version in the README to reflect the new
    version 1.22.
  • +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @andrei-tyk andrei-tyk requested review from a team as code owners May 13, 2024 10:53
    Copy link
    Contributor

    API Changes

    no api changes detected

    Copy link
    Contributor

    PR Description updated to latest commit (8c20728)

    Copy link
    Contributor

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves multiple changes across various configuration files, code files, and documentation to upgrade the Go version from 1.21 to 1.22. The changes are straightforward but numerous, requiring careful review to ensure all version references are correctly updated and that there are no compatibility issues with the new Go version.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Possible Bug: The function setGODEBUG in gateway/server.go sets the GODEBUG environment variable to enable deprecated TLS ciphers. This could potentially reintroduce security vulnerabilities that were addressed in Go 1.22.

    🔒 Security concerns

    Sensitive information exposure: The PR introduces changes that re-enable deprecated TLS ciphers by manipulating the GODEBUG environment variable. This could expose applications to older security vulnerabilities that have been deprecated for valid security reasons.

    Code feedback:
    relevant filegateway/server.go
    suggestion      

    Consider implementing a more secure method of handling deprecated ciphers rather than re-enabling them globally. This could involve selectively enabling them only where absolutely necessary or providing updates to clients that do not rely on these deprecated features. [important]

    relevant linegoDebugVal = "tlsrsakex=1," + os.Getenv("GODEBUG")

    Copy link
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Improve error handling for setting environment variables to avoid potential system inconsistencies

    Consider handling the error from os.Setenv more robustly. Instead of just logging a
    warning, it might be better to return the error to the caller or handle it in a way that
    does not potentially leave the system in an inconsistent state.

    gateway/server.go [1585-1587]

     err := os.Setenv("GODEBUG", goDebugVal)
     if err != nil {
    -    mainLog.Warn("Could not set GODEBUG=tlsrsakex=1, some deprecated ciphers might stop working")
    +    return fmt.Errorf("failed to set GODEBUG environment variable: %w", err)
     }
     
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a critical improvement in error handling that could prevent system inconsistencies, which is crucial for maintaining application stability.

    8
    Best practice
    Modify setGODEBUG to avoid global state changes and improve modularity

    To ensure that the setGODEBUG function does not inadvertently change the environment for
    other parts of the application, consider using a more localized approach to manage
    configuration settings, such as passing configuration objects or using context variables.

    gateway/server.go [1574-1589]

    -func setGODEBUG() {
    -    // With go 1.22 a few ciphers have been deprecated by the golang team due to security concerns
    -    // To mitigate this, we need to set the GODEBUG environment variable to re-enable the deprecated ciphers
    -    // to ensure that our clients can still upgrade to the lastest version of Tyk without any functionality breaking
    -    // For more details see: https://github.com/golang/go/issues/63413
    -    var goDebugVal string
    -    if os.Getenv("GODEBUG") == "" {
    -        goDebugVal = "tlsrsakex=1"
    -    } else {
    -        goDebugVal = "tlsrsakex=1," + os.Getenv("GODEBUG")
    -    }
    -    err := os.Setenv("GODEBUG", goDebugVal)
    -    if err != nil {
    -        mainLog.Warn("Could not set GODEBUG=tlsrsakex=1, some deprecated ciphers might stop working")
    -    }
    +func setGODEBUG(ctx context.Context) {
    +    // similar implementation
    +    // use ctx to pass and manage configuration without affecting global state
     }
     
    Suggestion importance[1-10]: 7

    Why: The suggestion promotes better practices by avoiding global state changes, which enhances the modularity and maintainability of the code. This is a good practice, especially in larger applications.

    7
    Maintainability
    Refactor setGODEBUG for clearer control flow and early exit on error

    Refactor the setGODEBUG function to directly return after setting the environment variable
    if no error occurred, simplifying the control flow and improving readability.

    gateway/server.go [1580-1587]

     if os.Getenv("GODEBUG") == "" {
         goDebugVal = "tlsrsakex=1"
     } else {
         goDebugVal = "tlsrsakex=1," + os.Getenv("GODEBUG")
     }
    -err := os.Setenv("GODEBUG", goDebugVal)
    -if err != nil {
    +if err := os.Setenv("GODEBUG", goDebugVal); err != nil {
         mainLog.Warn("Could not set GODEBUG=tlsrsakex=1, some deprecated ciphers might stop working")
    +    return
     }
     
    Suggestion importance[1-10]: 6

    Why: This suggestion improves the control flow and readability of the setGODEBUG function, which is beneficial for maintainability. However, it's a moderate improvement and not critical to functionality.

    6
    Enhancement
    Use strings.Join for concatenating environment variable settings for clarity and potential future scalability

    Instead of manually concatenating strings to form the GODEBUG value, use strings.Join for
    better readability and efficiency, especially if the list of settings might grow in the
    future.

    gateway/server.go [1583]

    -goDebugVal = "tlsrsakex=1," + os.Getenv("GODEBUG")
    +goDebugVal = strings.Join([]string{"tlsrsakex=1", os.Getenv("GODEBUG")}, ",")
     
    Suggestion importance[1-10]: 5

    Why: While the suggestion improves readability and potential scalability, it addresses a minor enhancement and does not impact the core functionality or performance significantly.

    5

    Copy link
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    1 similar comment
    Copy link
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    Copy link

    sonarcloud bot commented May 14, 2024

    Copy link

    sonarcloud bot commented May 14, 2024

    Please retry analysis of this Pull-Request directly on SonarCloud

    Copy link

    sonarcloud bot commented May 15, 2024

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    1 participant