Skip to content

Commit 1d4bb9e

Browse files
committed
Add information on mTLS
1 parent 56bc9f2 commit 1d4bb9e

File tree

1 file changed

+308
-0
lines changed

1 file changed

+308
-0
lines changed
Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
.. _user_guide_server_types:
2+
3+
======================================
4+
Working with DPF server configurations
5+
======================================
6+
7+
.. include:: ../../links_and_refs.rst
8+
9+
This tutorial demonstrates how to work with different DPF server types and configurations
10+
to optimize your workflow based on your specific needs.
11+
12+
DPF is based on a client-server architecture where PyDPF-Core acts as the Python client
13+
API communicating with a DPF Server. Understanding server types is essential for choosing
14+
the right configuration for your use case, whether you need maximum performance on a local
15+
machine, secure remote access with mTLS authentication, or distributed computation across a network.
16+
17+
:jupyter-download-script:`Download tutorial as Python script<server_types>`
18+
:jupyter-download-notebook:`Download tutorial as Jupyter notebook<server_types>`
19+
20+
21+
Understanding DPF server types
22+
------------------------------
23+
24+
There are three main server configurations available in PyDPF-Core:
25+
26+
- :class:`InProcessServer <ansys.dpf.core.server_types.InProcessServer>`: Direct communication
27+
within the same Python process (fastest, default since Ansys 2023 R1)
28+
- :class:`GrpcServer <ansys.dpf.core.server_types.GrpcServer>`: Network communication using
29+
gRPC protocol (enables remote and distributed computation)
30+
- :class:`LegacyGrpcServer <ansys.dpf.core.server_types.LegacyGrpcServer>`: Legacy gRPC
31+
communication for Ansys 2022 R1 and earlier versions
32+
33+
The choice of server type impacts performance, memory usage, and distributed computing capabilities.
34+
35+
36+
Starting a local InProcess server
37+
----------------------------------
38+
39+
The default and most efficient way to use PyDPF-Core is with an :class:`InProcessServer <ansys.dpf.core.server_types.InProcessServer>`.
40+
This configuration runs the DPF server directly within your Python process, eliminating data
41+
transfer overhead and providing the fastest performance.
42+
43+
First, import the necessary modules:
44+
45+
.. jupyter-execute::
46+
47+
# Import the ansys.dpf.core module as ``dpf``
48+
from ansys.dpf import core as dpf
49+
50+
# Import the examples module
51+
from ansys.dpf.core import examples
52+
53+
Start a local server using the default configuration:
54+
55+
.. jupyter-execute::
56+
57+
# Start a local DPF server with default InProcess configuration
58+
local_server = dpf.start_local_server()
59+
60+
# Display the server object
61+
print(local_server)
62+
63+
The server is now ready to be used for creating DPF objects.
64+
65+
66+
Using the local server
67+
-----------------------
68+
69+
Once you have started a local :class:`InProcessServer <ansys.dpf.core.server_types.InProcessServer>`,
70+
you can pass it to any DPF object constructor to ensure operations run on that specific server.
71+
72+
Create an |Operator| on the local server:
73+
74+
.. jupyter-execute::
75+
76+
# Instantiate a displacement Operator on the local server
77+
local_operator = dpf.operators.results.displacement(server=local_server)
78+
79+
# Display the Operator
80+
print(local_operator)
81+
82+
Create a |Model| on the local server:
83+
84+
.. jupyter-execute::
85+
86+
# Define the result file path using an example file
87+
result_file = examples.find_simple_bar()
88+
89+
# Instantiate a Model on the local server
90+
local_model = dpf.Model(result_file, server=local_server)
91+
92+
# Display basic information about the Model
93+
print(local_model)
94+
95+
96+
Starting a gRPC server
97+
----------------------
98+
99+
For distributed computation or remote access scenarios, use a :class:`GrpcServer <ansys.dpf.core.server_types.GrpcServer>`.
100+
This configuration enables network communication using the gRPC protocol, allowing you to
101+
connect from different machines or leverage distributed computing capabilities.
102+
103+
.. warning::
104+
105+
Starting with Ansys 2026 R1 (DPF 2026.1.0) and PyDPF-Core 0.15.0, DPF Server gRPC
106+
connections default to using authenticated mTLS (mutual TLS) transport for enhanced security.
107+
This change also applies to service packs for Ansys 2025 R2 SP03, 2025 R1 SP04, and 2024 R2 SP05.
108+
109+
For remote connections, you must configure mTLS certificates on both client and server machines.
110+
See :ref:`ref_dpf_server_secure_mode` for detailed information on certificate configuration.
111+
112+
Use the :class:`AvailableServerConfigs <ansys.dpf.core.server_factory.AvailableServerConfigs>`
113+
class to specify the server configuration:
114+
115+
.. jupyter-execute::
116+
117+
# Get the GrpcServer configuration
118+
grpc_server_config = dpf.AvailableServerConfigs.GrpcServer
119+
120+
# Start a local server with gRPC configuration
121+
grpc_server = dpf.start_local_server(config=grpc_server_config)
122+
123+
# Display the server object
124+
print(grpc_server)
125+
126+
Retrieve the server connection information:
127+
128+
.. jupyter-execute::
129+
130+
# Get the server IP address
131+
server_ip = grpc_server.ip
132+
133+
# Get the server port
134+
server_port = grpc_server.port
135+
136+
# Display connection information
137+
print(f"Server IP: {server_ip}")
138+
print(f"Server Port: {server_port}")
139+
140+
141+
Connecting to a remote gRPC server
142+
-----------------------------------
143+
144+
Once a :class:`GrpcServer <ansys.dpf.core.server_types.GrpcServer>` is running, you can connect
145+
to it from another machine or process using the :func:`connect_to_server <ansys.dpf.core.server.connect_to_server>`
146+
function. This enables distributed computation where data processing occurs on a remote server.
147+
148+
Connect to the gRPC server:
149+
150+
.. jupyter-execute::
151+
152+
# Connect to the remote gRPC server
153+
remote_server = dpf.connect_to_server(ip=server_ip, port=server_port, as_global=False)
154+
155+
# Display the connected server object
156+
print(remote_server)
157+
158+
Create DPF objects on the remote server:
159+
160+
.. jupyter-execute::
161+
162+
# Instantiate an Operator on the remote server
163+
remote_operator = dpf.operators.results.displacement(server=remote_server)
164+
165+
# Display the remote Operator
166+
print(remote_operator)
167+
168+
.. jupyter-execute::
169+
170+
# Instantiate a Model on the remote server
171+
remote_model = dpf.Model(result_file, server=remote_server)
172+
173+
# Display basic information about the remote Model
174+
print(remote_model)
175+
176+
Through the network using gRPC, a DPF server enables distributed computation capabilities.
177+
For examples of distributed workflows, see the gallery of examples.
178+
179+
180+
Configuring mTLS certificates for secure gRPC connections
181+
----------------------------------------------------------
182+
183+
When connecting to a remote gRPC server (starting with DPF 2026 R1 and PyDPF-Core 0.15.0),
184+
you need to configure mTLS certificates for secure communication. This applies to both the
185+
server machine and the client machine.
186+
187+
Set the certificate location using an environment variable
188+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189+
190+
The location of mTLS certificates is specified using the ``ANSYS_GRPC_CERTIFICATES`` environment
191+
variable. This must be set on both the server machine and the client machine.
192+
193+
On Windows:
194+
195+
.. jupyter-execute::
196+
:hide-output:
197+
198+
# Set the environment variable on Windows (run in PowerShell or Command Prompt)
199+
# os.environ['ANSYS_GRPC_CERTIFICATES'] = r'C:\path\to\certificates'
200+
pass
201+
202+
On Linux:
203+
204+
.. jupyter-execute::
205+
:hide-output:
206+
207+
# Set the environment variable on Linux (run in terminal)
208+
# export ANSYS_GRPC_CERTIFICATES=/path/to/certificates
209+
pass
210+
211+
For detailed information on generating mTLS certificates, see the
212+
`Generating certificates for mTLS <https://tools.docs.pyansys.com/version/stable/user_guide/secure_grpc.html#generating-certificates-for-mtls>`_
213+
documentation.
214+
215+
Disable mTLS for insecure mode (not recommended)
216+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
217+
218+
If you need to disable mTLS authentication and fall back to the previous insecure behavior,
219+
you can set the ``DPF_DEFAULT_GRPC_MODE`` environment variable to ``insecure`` on both
220+
client and server sides.
221+
222+
.. warning::
223+
224+
Disabling mTLS removes authentication and encryption, making your connection vulnerable
225+
to security threats. Only use insecure mode in trusted, isolated network environments.
226+
227+
On Windows:
228+
229+
.. jupyter-execute::
230+
:hide-output:
231+
232+
# Disable mTLS on Windows (not recommended for production)
233+
# os.environ['DPF_DEFAULT_GRPC_MODE'] = 'insecure'
234+
pass
235+
236+
On Linux:
237+
238+
.. jupyter-execute::
239+
:hide-output:
240+
241+
# Disable mTLS on Linux (not recommended for production)
242+
# export DPF_DEFAULT_GRPC_MODE=insecure
243+
pass
244+
245+
246+
Comparing server configurations
247+
--------------------------------
248+
249+
You can explicitly choose different server configurations using the :class:`AvailableServerConfigs <ansys.dpf.core.server_factory.AvailableServerConfigs>`
250+
class. This is useful when you need to test performance or compatibility with different server types.
251+
252+
Start servers with different configurations:
253+
254+
.. jupyter-execute::
255+
256+
# Get InProcessServer configuration
257+
in_process_config = dpf.AvailableServerConfigs.InProcessServer
258+
259+
# Start an InProcess server
260+
in_process_server = dpf.start_local_server(config=in_process_config, as_global=False)
261+
262+
# Display the InProcess server
263+
print(f"InProcess server: {in_process_server}")
264+
265+
.. jupyter-execute::
266+
267+
# Get GrpcServer configuration
268+
grpc_config = dpf.AvailableServerConfigs.GrpcServer
269+
270+
# Start a gRPC server
271+
grpc_server_2 = dpf.start_local_server(config=grpc_config, as_global=False)
272+
273+
# Display the gRPC server
274+
print(f"gRPC server: {grpc_server_2}")
275+
276+
.. jupyter-execute::
277+
278+
# Get LegacyGrpcServer configuration (for compatibility with older versions)
279+
legacy_grpc_config = dpf.AvailableServerConfigs.LegacyGrpcServer
280+
281+
# Start a legacy gRPC server
282+
legacy_grpc_server = dpf.start_local_server(config=legacy_grpc_config, as_global=False)
283+
284+
# Display the legacy gRPC server
285+
print(f"Legacy gRPC server: {legacy_grpc_server}")
286+
287+
288+
Key takeaways
289+
-------------
290+
291+
The choice of DPF server configuration depends on your specific requirements:
292+
293+
- Use :class:`InProcessServer <ansys.dpf.core.server_types.InProcessServer>` for local computations
294+
requiring maximum performance and minimal memory overhead (default since Ansys 2023 R1)
295+
296+
- Use :class:`GrpcServer <ansys.dpf.core.server_types.GrpcServer>` when you need distributed
297+
computation, remote access, or when running DPF on a different machine (available since Ansys 2022 R2)
298+
299+
- Starting with DPF 2026 R1, gRPC connections use mTLS authentication by default for enhanced security
300+
- Configure ``ANSYS_GRPC_CERTIFICATES`` environment variable on both client and server for mTLS
301+
- For more information, see :ref:`ref_dpf_server_secure_mode`
302+
303+
- Use :class:`LegacyGrpcServer <ansys.dpf.core.server_types.LegacyGrpcServer>` only for compatibility
304+
with Ansys 2022 R1 and earlier versions
305+
306+
All configurations use the same :func:`start_local_server <ansys.dpf.core.server.start_local_server>`
307+
function with different :class:`ServerConfig <ansys.dpf.core.server_factory.ServerConfig>` parameters,
308+
making it easy to switch between server types as your needs change.

0 commit comments

Comments
 (0)