Skip to content

Commit 4cd7dab

Browse files
committed
Implement endpoint in provisioning service in order to get fog node password, avoid interact with Redis and Vault from fog stream layer
1 parent 1134988 commit 4cd7dab

File tree

6 files changed

+176
-116
lines changed

6 files changed

+176
-116
lines changed

Gemfile.lock

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
connection_pool (2.4.1)
5-
redis (5.0.7)
6-
redis-client (>= 0.9.0)
7-
redis-client (0.15.0)
8-
connection_pool
4+
aws-eventstream (1.2.0)
5+
aws-sigv4 (1.6.0)
6+
aws-eventstream (~> 1, >= 1.0.2)
7+
json (2.6.3)
8+
vault (0.17.0)
9+
aws-sigv4
910

1011
PLATFORMS
12+
x64-mingw-ucrt
1113
x64-mingw32
1214

1315
DEPENDENCIES
14-
redis
16+
json
17+
vault
1518

1619
BUNDLED WITH
17-
1.17.2
20+
2.4.10

fog-stream-processing-layer/fog/fog_node.py

+11-51
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import re
1010
import requests
1111
from threading import Thread
12-
import redis
1312

1413
# Load configuration from environment variables
1514
PROVISIONING_SERVICE_URL = os.environ.get("PROVISIONING_SERVICE_URL")
@@ -20,13 +19,8 @@
2019
MQTT_BROKER_PASSWORD = os.environ.get("MQTT_BROKER_PASSWORD")
2120
MQTT_REAUTH_TOPIC = os.environ.get("MQTT_REAUTH_TOPIC", "request-auth")
2221
AUTH_SERVICE_URL = os.environ.get("AUTH_SERVICE_URL")
23-
VAULT_ADDRESS = os.environ.get("VAULT_ADDRESS", "http://vault:8200")
24-
REDIS_HOST = os.environ.get("REDIS_HOST", "redis")
25-
REDIS_PORT = int(os.environ.get("REDIS_PORT", 6379))
2622
FRAMES_OUTPUT_DIRECTORY = "frames_captured"
2723

28-
# Init redis connection
29-
redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=0)
3024
mac_address = ""
3125

3226
# Function to calculate the SHA-256 hash of a file
@@ -87,22 +81,6 @@ def get_challenge(mac_address):
8781
print("Error getting challenge:", e)
8882
return None
8983

90-
# Function to retrieve the Vault token from Redis
91-
def get_vault_token():
92-
"""
93-
Retrieve the Vault token from Redis.
94-
95-
Returns:
96-
str: Vault token.
97-
"""
98-
try:
99-
token = redis_client.get("vault_root_token")
100-
if token:
101-
return token.decode("utf-8")
102-
else:
103-
raise Exception("Vault token not found in Redis")
104-
except Exception as e:
105-
raise Exception("Error retrieving Vault token from Redis")
10684

10785
# Function to authenticate using CHAP (Challenge-Handshake Authentication Protocol)
10886
def authenticate_chap(mac_address, client_response):
@@ -125,29 +103,6 @@ def authenticate_chap(mac_address, client_response):
125103
print("Error during authentication:", e)
126104
return False
127105

128-
# Function to retrieve the node password from Vault
129-
def get_node_password(mac_address):
130-
"""
131-
Retrieve the node password from Vault.
132-
133-
Args:
134-
mac_address (str): MAC address of the device.
135-
136-
Returns:
137-
str: Node password.
138-
"""
139-
try:
140-
response = requests.get(
141-
f"{VAULT_ADDRESS}/v1/secret/data/users/{mac_address}",
142-
headers={"X-Vault-Token": get_vault_token()}
143-
)
144-
response_json = response.json()
145-
node_password = response_json["data"]["password"]
146-
return node_password
147-
except Exception as e:
148-
print("Error retrieving node password from Vault:", e)
149-
return None
150-
151106
# Callback function when the MQTT client connects to the broker
152107
def on_connect(client, userdata, flags, rc):
153108
"""
@@ -252,18 +207,23 @@ def authenticate(mac_address):
252207
print("Hash value of this code:", code_hash)
253208
challenge = get_challenge(mac_address)
254209
if challenge:
255-
node_password = get_node_password(mac_address)
256-
if node_password:
257-
client_response = hashlib.sha256((node_password + challenge + code_hash).encode()).hexdigest()
258-
return authenticate_chap(mac_address, client_response)
210+
password_response = requests.get(f"{PROVISIONING_SERVICE_URL}/get-fog-password?mac_address={mac_address}")
211+
if password_response.status_code == 200:
212+
password_data = password_response.json()
213+
node_password = password_data.get("fog_password")
214+
if node_password:
215+
client_response = hashlib.sha256((node_password + challenge + code_hash).encode()).hexdigest()
216+
return authenticate_chap(mac_address, client_response)
217+
else:
218+
print("Error retrieving node password from provisioning service")
259219
else:
260-
print("Error retrieving node password from Vault")
220+
print("Error getting node password from provisioning service")
261221
else:
262222
print("Error getting challenge")
263223
except Exception as e:
264224
print("Error during reauthentication:", e)
265225
return False
266-
226+
267227
# Initialize the MQTT client and set up callbacks
268228
client = mqtt.Client()
269229
client.username_pw_set(username=MQTT_BROKER_USERNAME, password=MQTT_BROKER_PASSWORD)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MQTT_BROKER_USERNAME=mosquitto
2+
MQTT_BROKER_PASSWORD=mosquitto
3+
MQTT_BROKER=localhost
4+
MQTT_PORT=1883
5+
MQTT_TOPIC=iot-camera-frames
6+
MQTT_REAUTH_TOPIC=request-auth
7+
KAFKA_BROKER=localhost:9092
8+
KAFKA_TOPIC=iot-camera-frames
9+
REDIS_HOST=localhost
10+
REDIS_PORT=6379
11+
REDIS_EXPIRATION_CHANNEL=__keyevent@0__:expired
12+
VAULT_ADDRESS=http://localhost:8200
13+
MONGO_HOST=localhost
14+
MONGO_PORT=27017

framework-extended-services-layer/docker-compose.yml

+10-47
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
11
version: "3"
22

3-
43
services:
54

65
# Flask-based authentication service for authorization and authentication
76
auth_service:
8-
build:
9-
context: ./authentication
10-
dockerfile: Dockerfile
11-
container_name: auth-service-container
7+
image: ssanchez11/smart_highway_net_auth_service:0.0.1
8+
container_name: auth-service
129
env_file:
1310
- ./.env
1411
environment:
1512
- REDIS_HOST=${REDIS_HOST}
1613
- REDIS_PORT=${REDIS_PORT}
1714
- VAULT_ADDRESS=${VAULT_ADDRESS}
18-
- VAULT_PORT=${VAULT_PORT}
1915
ports:
2016
- "5000:5000"
21-
links:
22-
- vault
23-
- redis
24-
depends_on:
25-
- vault
26-
- redis
2717
networks:
28-
- smart-highway-net
29-
18+
- smart-highway-net
3019

3120
notifier:
32-
build:
33-
context: ./notifier
34-
dockerfile: Dockerfile
21+
image: ssanchez11/smart_highway_net_notifier_service:0.0.1
3522
container_name: notifier-service
3623
env_file:
3724
- ./.env
@@ -42,19 +29,11 @@ services:
4229
- MQTT_BROKER=${MQTT_BROKER}
4330
- MQTT_PORT=${MQTT_PORT}
4431
- MQTT_REAUTH_TOPIC=${MQTT_REAUTH_TOPIC}
45-
links:
46-
- mosquitto
47-
- redis
48-
depends_on:
49-
- mosquitto
50-
- redis
5132
networks:
52-
- smart-highway-net
33+
- smart-highway-net
5334

5435
provision:
55-
build:
56-
context: ./provision
57-
dockerfile: Dockerfile
36+
image: ssanchez11/smart_highway_net_provision_service:0.0.1
5837
container_name: provision-service
5938
env_file:
6039
- ./.env
@@ -63,20 +42,12 @@ services:
6342
- REDIS_PORT=${REDIS_PORT}
6443
- MONGO_HOST=${MONGO_HOST}
6544
- MONGO_PORT=${MONGO_PORT}
66-
links:
67-
- mosquitto
68-
- redis
69-
depends_on:
70-
- mosquitto
71-
- redis
7245
networks:
73-
- smart-highway-net
46+
- smart-highway-net
7447

7548
integrator:
76-
build:
77-
context: ./integrator
78-
dockerfile: Dockerfile
79-
container_name: integrator
49+
image: ssanchez11/smart_highway_net_integrator_service:0.0.1
50+
container_name: integrator-service
8051
env_file:
8152
- ./.env
8253
environment:
@@ -86,16 +57,8 @@ services:
8657
- MQTT_TOPIC=${MQTT_TOPIC}
8758
- KAFKA_BROKER=${KAFKA_BROKER}
8859
- KAFKA_TOPIC=${KAFKA_TOPIC}
89-
depends_on:
90-
- zookeeper
91-
- kafka
92-
- mosquitto
93-
links:
94-
- zookeeper
95-
- kafka
96-
- mosquitto
9760
networks:
98-
- smart-highway-net
61+
- smart-highway-net
9962

10063
networks:
10164
smart-highway-net:

0 commit comments

Comments
 (0)