Note
🗒️ Este respositorio es público y de prueba para comprender y prácticar el uso de workflows con SonarQube 📚🧪. Eres libre de forkearlo y hacer tus propias pruebas🤝🏻. Si te ha servido, una estrella estaría genial⭐😊. Si aplicarías mejoras, abre una pull request con la palabra 'MEJORA' al principio del título y crearé una rama nueva con TODAS las mejoras que se propongan💡.
- Postgres como DB de SonarQube
- SonarQube
- Ejecutar:
docker-compose up -d
- Ngrok download
- Autenticarse en CMD
- Alojar la dirección de SoanrQube:
ngrok http 9000
localhost:9000- user:
adminpass:admin - New pass / My Account / Security / Generate Tokens:
- Repo Settings / Secrets and variables -> Actions / New repository secret
- Name:
SONAR_TOKEN - Value:
SONARQUBE TOKEN
- Name:
- Update secret
- El fichero
workflow.ymlen.github/workflowsdefine las tareas a realizar - Para que funcione correctamente con SonarQube y se ejecute el análisis, modificar en
workflow.ymlel parámetro-Dsonar.host.url=<URL SONARQUBE> \
Caution
Tanto para Pinggy como Ngrok, el enlace generado se debe escribir tanto en el apartado de Verificar SonarQube como en el host.url del workflow.yml
git add .git commit -m "Jobs"git push -u origin main
Note
Para comprobar el funcionamiento de SonarQube respecto a este repositorio, se especifica a continuación los pasos para visualizar los efectos que tiene:
- Asegurarse de tener el codigo del fichero
examples/Main.java.txtensrc/com/example/sqlinjection/Main.java. - Hacemos
git add .,git commit -m "init"ygit push -u origin main - El workflow lo detectará y comenzará el analisis.
- Al finalizar accedemos a la URL donde tenemos sonar y vemos el analisis (el estado será
✅Passed) - Copiamos el contenido de
examples/Vuln.java.txtensrc/com/example/sqlinjection/Main.javay repetimos el proceso. - Se ven el análisis con el estado
❌Failed - Para corregir esos errores copiamos el contenido de
examples/VulnSolved2.java.txten el ficherosrc/com/example/sqlinjection/Main.java - Volvemos a realizar el proceso de git y visualizar sonar
Warning
Es posible que aparezca como ❌Failed debido a que habrá cosas por cubrir como tests o pruebas en el código. Puede ocurrir que no interese mostrar esos error por lo que se debe crear una Quality Gate en SonarQube, estableciendo todo a 0% excepto los Security Hotspots Review
Note
🗒️ This repository is public for making custom tests and for understanding and practicing the usage of workflows with SonarQube integrated 📚🧪. You're free to fork it and make your own tests🤝🏻. If this served you, I will be grateful for the repo to be starred⭐😊. If you would apply improvements please open a pull request with the word 'UPGRADE' in the title field and I will create a new branch with ALL the proposed improvements💡.
- Postgres as a DB for SonarQube
- SonarQube
- Run:
docker-compose up -d
- Ngrok download
- Authenticate with CMD
- Host the SoanrQube route:
ngrok http 9000
localhost:9000- user:
adminpass:admin - New pass / My Account / Security / Generate Tokens:
- Repo Settings / Secrets and variables -> Actions / New repository secret
- Name:
SONAR_TOKEN - Value:
SONARQUBE TOKEN
- Name:
- Update secret
- The file
workflow.ymlin.github/workflowsdefines the tasks to run - To make this work correctly with SonarQube and run the analysis, modify in
workflow.ymlthe-Dsonar.host.url=<URL SONARQUBE> \parameter
Caution
For both Pinggy and Ngrok generated links, it must be in both Verificar SonarQube and host.url sections from workflow.yml
git add .git commit -m "Jobs"git push -u origin main
Note
To check SonarQube behavior, follow the next steps to watch the results:
- Ensure having the code from
examples/Main.java.txtinsrc/com/example/sqlinjection/Main.java. - Make
git add .,git commit -m "init"andgit push -u origin main - The workflow will detect it and start the analysis.
- At the end, enter the URL where we have SonarQube to view the analysis (the status will be
✅Passed) - Copy the content from the
examples/Vuln.java.txtfile insrc/com/example/sqlinjection/Main.javaand repeat the process. - The analysis status will be
❌Failed - To amend these errors copy the content from the
examples/VulnSolved2.java.txtfile in thesrc/com/example/sqlinjection/Main.javafile - Repeat the git process and watch SonarQube results.
Warning
Is probably that it would appear ❌Failed again due some errors that should be solved like adding tests in the code. If you're not interested in SonarQube to show these errors, you may create a Quality Gate in SonarQube, setting every parameter to 0% except the Security Hotspots Review parameter.