Skip to content

Commit

Permalink
Merge branch 'main' into k8s-dabase-update
Browse files Browse the repository at this point in the history
  • Loading branch information
JOT85 authored Jan 24, 2022
2 parents 61bb488 + a3fcb3b commit 596d28c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
15 changes: 8 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [Development-Angular](#development-angular)
* [Testing](#testing)

Wow you landed on the contribution page how awesome you must be to help out and add value to his project! We thank you very much for this and we really appricate your help. We will reward contributors with recongnision on the contributors list of SKF and for people who add new feutures or fix / report security issues we will give you a free OWASP-SKF t-shirt! If you are really bad ass and you add major improvements then you will receive a hoodie of OWASP-SKF with your name on it!
Wow you landed on the contribution page how awesome you must be to help out and add value to his project! We thank you very much for this and we really appreciate your help. We will reward contributors with recognition on the contributors list of SKF and for people who add new feutures or fix / report security issues we will give you a free OWASP-SKF t-shirt! If you are really bad ass and you add major improvements then you will receive a hoodie of OWASP-SKF with your name on it!

Below are the 2 different parts of SKF and how you can contribute to it, please always make sure that the quality we try to achieve remains intact. Also when you have questions or want to discuss your implementation / contribution please locate us on Gitter.im chat: [![Join the chat at https://gitter.im/Security-Knowledge-Framework/Lobby](https://badges.gitter.im/Security-Knowledge-Framework/Lobby.svg)](https://gitter.im/Security-Knowledge-Framework/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand All @@ -15,12 +15,12 @@ Again thank you for your help, you rock!
## <a name="development-api"></a>Development SKF-API

1. Fork and clone https://github.com/blabla1337/skf-flask
2. pip3.6 install -r requirements.txt
2. pip3 install -r requirements.txt
3. export FLASK_APP=skf/app.py
4. export PYTHONPATH=.:$PYTHONPATH
5. export FLASK_DEBUG=1
6. export SKF_JWT_SECRET='True'
7. python3.6 skf/app.py
7. python3 skf/app.py
8. Run the manual test first to verify if everything is good
```
coverage run tests/run.py test
Expand All @@ -30,12 +30,13 @@ coverage run tests/run.py test
## <a name="development-angular"></a>Development SKF-ANGULAR

1. Fork and clone https://github.com/blabla1337/skf-flask
2. cd Angular
2. cd Angular2
3. npm install
4. ng serve --host=0.0.0.0
4. OR edit the package.json in Angular folder and remove --env=prod example: "start": "ng serve --host=0.0.0.0"
4. ng serve --host=0.0.0.0<br/>
OR</br>
edit the package.json in Angular folder and remove --env=prod example: "start": "ng serve --host=0.0.0.0"
5. npm start
6. Run the manual test in the Angular dir first to verify if everything is good
6. Run the manual test in the Angular2 dir first to verify if everything is good
```
npm test
```
Expand Down
11 changes: 6 additions & 5 deletions Docker/alpine-cloud/k8s/Deployment_backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ spec:
configMapKeyRef:
name: skf-flask-back
key: SKF_LABS_DEPLOY_MODE
- name: GOOGLE_CREDENTIALS
valueFrom:
configMapKeyRef:
name: skf-flask-back
key: GOOGLE_CREDENTIALS
# Enable when using Google GKE
# - name: GOOGLE_CREDENTIALS
# valueFrom:
# configMapKeyRef:
# name: skf-flask-back
# key: GOOGLE_CREDENTIALS
---
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Creates a nice badge for your website SSL/TLS security settings based on the Qua
Licensed under the [creative commons](http://creativecommons.org/licenses/by-nd/3.0/nl/) license

## <a name="contributors"></a>Contributors
- [Imanuel Febie](https://github.com/tuffgniuz)
- [Glenn ten Cate](https://twitter.com/FooBar_testing_)
- [Riccardo ten Cate](https://twitter.com/RiieCco)
- Lucas Luitjes
Expand Down
16 changes: 15 additions & 1 deletion skf/rabbit_mq_workers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def delete_all(instance_name, user_id):
delete_ingress(instance_name, user_id)
delete_service(instance_name, user_id)
delete_deployment(instance_name, user_id)
delete_namespace(user_id)

def delete_deployment(instance_name, user_id):
try:
Expand All @@ -18,7 +19,20 @@ def delete_deployment(instance_name, user_id):
grace_period_seconds=5))
#print("Deployment deleted. status='%s'" % str(api_response.status))
except:
print('Error deleteing deployment')
print('Error deleting deployment')

def delete_namespace(user_id):
try:
config.load_kube_config()
api_instance = client.CoreV1Api()
api_response = api_instance.delete_namespace(
name=user_id,
body=client.V1DeleteOptions(
propagation_policy='Foreground',
grace_period_seconds=5))
#print("Namespace deleted. status='%s'" % str(api_response.status))
except:
print('Error deleting namespace')

def delete_service(instance_name, user_id):
try:
Expand Down
39 changes: 18 additions & 21 deletions skf/rabbit_mq_workers/deployment-worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
creds = pika.PlainCredentials('admin', 'admin-skf-secret')
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=settings.RABBIT_MQ_CONN_STRING,
credentials=creds
credentials=creds,
))
channel = connection.channel()
channel.queue_declare(queue='deployment_qeue')

labs_domain = os.environ['SKF_LABS_DOMAIN']
subdomain_deploy = os.environ.get('SKF_LABS_DEPLOY_MODE') == 'subdomain'
if subdomain_deploy == 'subdomain':
if subdomain_deploy:
(labs_protocol, labs_domain) = re.compile('(.*:\/\/)?(.*)').match(labs_domain).groups()
if labs_protocol is None:
labs_protocol = 'http://'
Expand All @@ -36,7 +36,7 @@ def deploy_container(rpc_body):
return {'message': 'Failed to deploy, error K8s API create service call!'}
time.sleep(15)
response = get_service_exposed_ip(deployment, user_id)
if subdomain_deploy == 'subdomain':
if subdomain_deploy:
hostname = '{}-{}.{}'.format(deployment, user_id, labs_domain)
networking_v1_beta1_api = client.NetworkingV1beta1Api()
ingress_err = create_ingress(networking_v1_beta1_api, hostname, deployment, service_port, user_id)
Expand Down Expand Up @@ -92,24 +92,21 @@ def create_deployment(deployment, user_id):
return {'message': 'Failed to deploy, error K8s API create call!'}

def create_service_for_deployment(deployment, user_id):
try:
config.load_kube_config()
api_instance = client.CoreV1Api()
service = client.V1Service()
service.api_version = "v1"
service.kind = "Service"
service.metadata = client.V1ObjectMeta(name=deployment)
spec = client.V1ServiceSpec()
spec.type = "NodePort"
spec.selector = {"app": deployment}
# Why a random port?
random_port = random.randrange(40000, 60000)
spec.ports = [client.V1ServicePort(protocol="TCP", port=random_port, target_port=5000)]
service.spec = spec
response = api_instance.create_namespaced_service(namespace=user_id, body=service)
return response
except:
return {'message':'Failed to deploy, error K8s API ceate service call!'}
config.load_kube_config()
api_instance = client.CoreV1Api()
service = client.V1Service()
service.api_version = "v1"
service.kind = "Service"
service.metadata = client.V1ObjectMeta(name=deployment)
spec = client.V1ServiceSpec()
spec.type = "NodePort"
spec.selector = {"app": deployment}
# Why a random port?
random_port = random.randrange(40000, 60000)
spec.ports = [client.V1ServicePort(protocol="TCP", port=random_port, target_port=5000)]
service.spec = spec
response = api_instance.create_namespaced_service(namespace=user_id, body=service)
return random_port

def get_service_exposed_ip(deployment, user_id):
try:
Expand Down

0 comments on commit 596d28c

Please sign in to comment.