Skip to content

Commit 36ab940

Browse files
committed
secure connections via force_tls
1 parent 50833a0 commit 36ab940

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

docs/EnvVars.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Environment Variable | Description | Default
66
| `SW_AGENT_INSTANCE` | The name of the Python service instance | Randomly generated |
77
| `SW_AGENT_NAMESPACE` | The agent namespace of the Python service | unset |
88
| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | `127.0.0.1:11800` |
9+
| `SW_AGENT_FORCE_TLS` | Use TLS for communication with server (no cert required) | `False` |
910
| `SW_AGENT_PROTOCOL` | The protocol to communicate with the backend OAP, `http`, `grpc` or `kafka`, **we highly suggest using `grpc` in production as it's well optimized than `http`**. The `kafka` protocol provides an alternative way to submit data to the backend. | `grpc` |
1011
| `SW_AGENT_AUTHENTICATION` | The authentication token to verify that the agent is trusted by the backend OAP, as for how to configure the backend, refer to [the yaml](https://github.com/apache/skywalking/blob/4f0f39ffccdc9b41049903cc540b8904f7c9728e/oap-server/server-bootstrap/src/main/resources/application.yml#L155-L158). | unset |
1112
| `SW_AGENT_LOGGING_LEVEL` | The logging level, could be one of `CRITICAL`, `FATAL`, `ERROR`, `WARN`(`WARNING`), `INFO`, `DEBUG` | `INFO` |
@@ -27,5 +28,5 @@ Environment Variable | Description | Default
2728
| `SW_KAFKA_REPORTER_TOPIC_SEGMENT` | Specifying Kafka topic name for Tracing data. | `skywalking-segments` |
2829
| `SW_KAFKA_REPORTER_CONFIG_key` | The configs to init KafkaProducer. it support the basic arguments (whose type is either `str`, `bool`, or `int`) listed [here](https://kafka-python.readthedocs.io/en/master/apidoc/KafkaProducer.html#kafka.KafkaProducer) | unset |
2930
| `SW_CELERY_PARAMETERS_LENGTH`| The maximum length of `celery` functions parameters, longer than this will be truncated, 0 turns off | `512` |
30-
| `SW_AGENT_PROFILE_ACTIVE` | If `True`, Python agent will enable profile when user create a new profile task. Otherwise disable profile. | `False` |
31-
| `SW_PROFILE_TASK_QUERY_INTERVAL` | The number of seconds between two profile task query. | `20` |
31+
| `SW_AGENT_PROFILE_ACTIVE` | If `True`, Python agent will enable profile when user create a new profile task. Otherwise disable profile. | `False` |
32+
| `SW_PROFILE_TASK_QUERY_INTERVAL` | The number of seconds between two profile task query. | `20` |

skywalking/agent/protocol/grpc.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@
3636
class GrpcProtocol(Protocol):
3737
def __init__(self):
3838
self.state = None
39-
self.channel = grpc.insecure_channel(config.collector_address, options=(('grpc.max_connection_age_grace_ms',
40-
1000 * config.GRPC_TIMEOUT),))
39+
40+
if config.force_tls:
41+
self.channel = grpc.secure_channel(config.collector_address, grpc.ssl_channel_credentials(),
42+
options=(('grpc.max_connection_age_grace_ms',
43+
1000 * config.GRPC_TIMEOUT),))
44+
else:
45+
self.channel = grpc.insecure_channel(config.collector_address, options=(('grpc.max_connection_age_grace_ms',
46+
1000 * config.GRPC_TIMEOUT),))
47+
4148
if config.authentication:
4249
self.channel = grpc.intercept_channel(
4350
self.channel, header_adder_interceptor('authentication', config.authentication)

skywalking/client/http.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525

2626
class HttpServiceManagementClient(ServiceManagementClient):
2727
def __init__(self):
28+
proto = 'https://' if config.force_tls else 'http://'
29+
self.url_instance_props = proto + config.collector_address.rstrip('/') + '/v3/management/reportProperties'
30+
self.url_heart_beat = proto + config.collector_address.rstrip('/') + '/v3/management/keepAlive'
2831
self.session = requests.Session()
2932

3033
def fork_after_in_child(self):
3134
self.session.close()
3235
self.session = requests.Session()
3336

3437
def send_instance_props(self):
35-
url = 'http://' + config.collector_address.rstrip('/') + '/v3/management/reportProperties'
36-
res = self.session.post(url, json={
38+
res = self.session.post(self.url_instance_props, json={
3739
'service': config.service_name,
3840
'serviceInstance': config.service_instance,
3941
'properties': [{
@@ -48,8 +50,7 @@ def send_heart_beat(self):
4850
config.service_name,
4951
config.service_instance,
5052
)
51-
url = 'http://' + config.collector_address.rstrip('/') + '/v3/management/keepAlive'
52-
res = self.session.post(url, json={
53+
res = self.session.post(self.url_heart_beat, json={
5354
'service': config.service_name,
5455
'serviceInstance': config.service_instance,
5556
})
@@ -58,16 +59,17 @@ def send_heart_beat(self):
5859

5960
class HttpTraceSegmentReportService(TraceSegmentReportService):
6061
def __init__(self):
62+
proto = 'https://' if config.force_tls else 'http://'
63+
self.url_report = proto + config.collector_address.rstrip('/') + '/v3/segment'
6164
self.session = requests.Session()
6265

6366
def fork_after_in_child(self):
6467
self.session.close()
6568
self.session = requests.Session()
6669

6770
def report(self, generator):
68-
url = 'http://' + config.collector_address.rstrip('/') + '/v3/segment'
6971
for segment in generator:
70-
res = self.session.post(url, json={
72+
res = self.session.post(self.url_report, json={
7173
'traceId': str(segment.related_traces[0]),
7274
'traceSegmentId': str(segment.segment_id),
7375
'service': config.service_name,

0 commit comments

Comments
 (0)