Coder Social home page Coder Social logo

globocom / huskyci Goto Github PK

View Code? Open in Web Editor NEW
569.0 29.0 138.0 19.92 MB

Performing security tests inside your CI

Home Page: https://huskyci.opensource.globo.com

License: BSD 3-Clause "New" or "Revised" License

Go 94.41% Dockerfile 1.14% Makefile 1.09% Shell 3.37% Procfile 0.01%
vulnerabilities continuous-integration golang python javascript ruby-on-rails static-analysis security-automation gosec brakeman bandit safety npm-audit yarn-audit gitlab-ci security-tools hacktoberfest hacktoberfest2023-accepted

huskyci's Issues

ReadOutput() from api.go could return STDERR as well

func (d Docker) ReadOutput() (string, error) {
	dockerHost := os.Getenv("DOCKER_HOST")
	URL := "http://" + dockerHost + "/v1.24/containers/" + d.CID + "/logs?stdout=1"
	resp, err := http.Get(URL)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(body), err
}

URL := "http://" + dockerHost + "/v1.24/containers/" + d.CID + "/logs?stdout=1"
is being used but it would be nice to check if

URL := "http://" + dockerHost + "/v1.24/containers/" + d.CID + "/logs?stderr=1"
is also returns something!

Include into dockers' cmd an auth command to git clone private repositories

The following commands may need to use git private and pub ssh keys to clone private repositories:

git clone %GIT_REPO% code --quiet && cd code && enry --json | tr -d '\r\n'
cd src; git clone %GIT_REPO% code --quiet && cd code && /go/bin/gas -quiet -fmt=json -log=log.txt -out=results.json ./... 2> /dev/null ; jq -j -M -c . results.json

Change limitEnryScan to 0 to force Husky always start enry

Although it would be nice avoiding a new Enry scan every time Husky starts an analysis, this might be necessary to guarantee that any vulnerability is not detected if a new language is inserted.

Example:

A new config.sh is added into the repository that contains hardcoded passwords. Enry may not detect this file for the futures 9 scans in the worst case scenario.

Standardize how error messages are sent to the user

Create a new standard for all error messages to be used by Husky as suggested by @nettoclaudio:

I would returned the echo.NewHTTPError(http.StatusNotFound, "analysis not found") instead that. I think that's the standardized by Echo web framework.

Ref.: https://echo.labstack.com/guide/error-handling

Cannot find package "github.com/globocom/glbgelf"

After installing the environment via make install, the following error is being found:

$ docker logs huskyCIAPI
server.go:10:2: cannot find package "github.com/globocom/glbgelf" in any of:
	/go/src/github.com/globocom/huskyci/vendor/github.com/globocom/glbgelf (vendor tree)
	/usr/local/go/src/github.com/globocom/glbgelf (from $GOROOT)
	/go/src/github.com/globocom/glbgelf (from $GOPATH)

Create husky client to be downloaded and executed during a CI

Husky must have a client with the following features:

  • Send request to Husky API.
  • From time to time, check if the scan has already finished.
  • Receive eventual parameters (name of the scan, ignore files, how paranoid the scan should be, etc.)
  • Fail/Pass the pipeline.

Verify if image exists and get image if it doesn't exist

The images used in Docker to start the containers with security tests is downloaded once from Vagrant script. However, image management must be done on the API. If the images are removed from Docker, the security tests will fail.

The HuskyCI API needs to know if images that deal with security tests exist and, if not, get from the correspondent registry. After that, the logic follows the current procedure.

analysis.go: 302 response missing Location header

When building Husky client, the following error is being received when trying to GET an analysis:

Error during GET to Husky API: Get http://localhost:9999/husky/g3i2Yqrwv1hQfejdQehSMIOtcmOZsJCJ: 302 response missing Location header

The problem might be at return c.JSON(http.StatusFound, analysisResult) from analysis.go. A different status code like StatusOK would solve this problem.

Container's logs are coming with different outputs after refactor

Example:

Cloning into 'code'...
remote: Counting objects: 1620, done.
remote: Compressing objects: 100% (1141/1141), done.
remote: Total 1620 (delta 420), reused 1594 (delta 398), pack-reused 0
Receiving objects: 100% (1620/1620), 3.69 MiB | 2.15 MiB/s, done.
Resolving deltas: 100% (420/420), done.
{"Dockerfile":["Dockerfile"],"Go":["api/health.go","api/health_test.go","api/mock.go","api/scan.go","api/scan_test.go","api/server.go","cmd/root.go","cmd/server/server.go","cmd/server/server_test.go","cmd/worker/worker.go","cmd/worker/worker_test.go","db/mock.go","db/mongodb/mongo.go","db/mongodb/mongo_test.go","db/storage.go","main.go","queue/mock.go","queue/queue.go","scan/clair.go","scan/mock.go","scan/scan.go","scan/scheduler/default.go","scan/scheduler/default_test.go","scan/scheduler/mock.go","scan/scheduler/scheduler.go","scan/worker/default.go","scan/worker/default_test.go"],"Makefile":["Makefile"]}

Expected:

{"Dockerfile":["Dockerfile"],"Go":["api/health.go","api/health_test.go","api/mock.go","api/scan.go","api/scan_test.go","api/server.go","cmd/root.go","cmd/server/server.go","cmd/server/server_test.go","cmd/worker/worker.go","cmd/worker/worker_test.go","db/mock.go","db/mongodb/mongo.go","db/mongodb/mongo_test.go","db/storage.go","main.go","queue/mock.go","queue/queue.go","scan/clair.go","scan/mock.go","scan/scan.go","scan/scheduler/default.go","scan/scheduler/default_test.go","scan/scheduler/mock.go","scan/scheduler/scheduler.go","scan/worker/default.go","scan/worker/default_test.go"],"Makefile":["Makefile"]}

Refactor DockerHostsConfig struct

Change DockerHostsConfig struct so that it stores:

  • Addresses
  • Protocol
  • DockerAPIVersion

@mdjunior : "The DockerAPI port that will be the same on all hosts?
Maybe it was better if the data structure allowed a list of hosts, where each host would be a structure with Address and Port (and eventually other things, such as certificates and keys)."

// DockerHostsConfig represents Docker Hosts configuration.
type DockerHostsConfig struct {
	Addresses     []string
	DockerAPIPort int

@mdjunior : "The http protocol and docker version is hardcoded. Maybe it was better if this information was entered in the DockerHosts data structure in context/config.go."

// HealthCheckAPI returns true if a 200 status code is received or false otherwise.
func HealthCheckAPI(dockerHost string) error {
	URL := fmt.Sprintf("http://%s/v1.24/version", dockerHost)

It could be optional git cloning repositories via SSH inside containers (security Tests)

Security tests configs could have cmds to git clone inside container with or without using SSH keys:

For example cmdSSHAuth and cmdNonAuth:

enry:
  name: enry
  image: huskyci/enry
  cmdSSHAuth: |+
    mkdir -p ~/.ssh &&
    echo 'GIT_PRIVATE_SSH_KEY' > ~/.ssh/huskyci_id_rsa &&
    chmod 600 ~/.ssh/huskyci_id_rsa &&
    echo "IdentityFile ~/.ssh/huskyci_id_rsa" >> /etc/ssh/ssh_config &&
    echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&
    git clone -b %GIT_BRANCH% --single-branch %GIT_REPO% code --quiet 2> /tmp/errorGitCloneEnry
    if [ $? -eq 0 ]; then
      cd code
      enry --json | tr -d '\r\n'
    else
      echo "ERROR_CLONING"
      cat /tmp/errorGitCloneEnry
    fi
  cmdNonAuth: |+
    git clone -b %GIT_BRANCH% --single-branch %GIT_REPO% code --quiet 2> /tmp/errorGitCloneEnry
    if [ $? -eq 0 ]; then
      cd code
      enry --json | tr -d '\r\n'
    else
      echo "ERROR_CLONING"
      cat /tmp/errorGitCloneEnry
    fi
  language: Generic
  default: true
  timeOutInSeconds: 60

Gathering metrics (Brainstorm)

For statistics purposes, it would be a good idea to implement the field numAnalysis into Repository.

An increment function is also needed when updating it into MongoDB.

type Repository struct {
	ID               bson.ObjectId  `bson:"_id,omitempty"`
	URL              string         `bson:"URL" json:"repositoryURL"`
	SecurityTests    []SecurityTest `bson:"securityTests" json:"securityTests"`
	SecurityTestName []string       `bson:"securityTestName,omitempty" json:"securityTestName"`
	VM               string         `bson:"VM" json:"vm"`
	CreatedAt        time.Time      `bson:"createdAt" json:"createdAt"`
	DeletedAt        time.Time      `bson:"deletedAt" json:"deletedAt"`
	Languages        []Language     `bson:"languages" json:"languages"`
}

Add a return statement into analysis.go

enrySecurityTestQuery := map[string]interface{}{"name": "enry"}
		enrySecurityTestResult, err := FindOneDBSecurityTest(enrySecurityTestQuery)
		if err != nil {
			fmt.Println("Error finding enry securityTest:", err)
                 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.