This article shows how to harden the OPC UA server of the gateway for sites with IT security requirements: encryption imposed, named users, a server certificate signed by your certification authority (CA), and connections accepted only from approved clients. It follows the order in which the settings are best applied on a running installation.
The OPC UA driver page is the reference for every parameter (2.3 Server parameters, 4. Security). This article is the procedure.
Every change to the gateway parameters, and every certificate import or approval, restarts the OPC UA gateway: connected clients reconnect. Plan the changes outside operating hours, and keep a client such as UaExpert at hand to test after each step.
A new server gateway (Mode server, default Port 26543) is open by design, so that any client can connect during commissioning:
None, Sign, SignAndEncrypt), with the library's default security policies, including deprecated ones;The endpoint URL to enter in a client is opc.tcp://<address of the gateway>:26543.
In the gateway parameters:
SignAndEncrypt only.Basic256Sha256 and Aes128_Sha256_RsaOaep. Add Aes256_Sha256_RsaPss only if your clients require it (see below).None or Sign no longer finds a matching endpoint.Do not select None (no security), nor Basic128Rsa15 or Basic256: these two policies are deprecated by the OPC Foundation.
If a selected policy is not supported by the OPC UA library installed on the device, it is ignored with a warning in the gateway log; Aes256_Sha256_RsaPss in particular needs a recent library. If none of the selected modes or policies is usable, the server does not start (it never falls back to an open endpoint) and the gateway log explains why. The Certificates › Server certificate window shows the library version and whether Aes256_Sha256_RsaPss is available.
Do both. With an empty User list, any user name and password is accepted, so unchecking Allow anonymous alone does not restrict access. With users defined and Allow anonymous still checked, anonymous sessions remain possible.
Give each client system its own account, so that one can be removed without touching the others. The passwords are stored in the gateway configuration: restrict access to the gateway web interface and to its backups accordingly (see Security).
A certificate issued by your CA lets clients trust the server through the CA, instead of approving a self-signed certificate on each client every year. The gateway must be started; the commands are in the Certificates menu of the gateway's address panel.
OPC UA clients check that the application URI announced by the server is identical to the URI written in its certificate, and that the host name they connect to is in the certificate.
urn:site-geneva:wbox:opcua.wbox-opcua.example.local, 10.20.0.15.| Field | Value |
|---|---|
| Common name (CN) | Required. The name of the server, for example wbox-opcua.example.local. |
| Organization (O), Organizational unit (OU) | As required by your CA. |
| Country (C, 2 letters) | Default CH. |
| Application URI (SAN URI) | Prefilled with Application URI. Keep it identical. |
| DNS names (comma separated) | Prefilled with Endpoint host names; keep only the DNS names. |
| IP addresses (comma separated) | The IP addresses the clients use. |
| RSA key size | 2048, 3072 (default) or 4096. |
.csr.pem file to your CA. The private key never leaves the device. The request asks for both the server and client authentication usages: ask the CA to keep them, together with the URI, DNS names and IP addresses of the request.The CSR stays pending until its certificate is imported: the Server certificate window offers Download pending CSR in the meantime. Generating a new CSR replaces the pending one, and only the certificate issued for the last CSR can then be imported.
-----BEGIN CERTIFICATE-----) or choose its file, then click Import. If the file also contains the CA chain, only the server certificate is kept.A CA-issued certificate is never replaced automatically. From 30 days before it expires, the gateway log shows a daily warning (server certificate ... expires on ...), and an error once it has expired: clients then refuse the connection. To renew it, generate a new CSR (the form is prefilled from the current certificate) and import the new certificate.
To go back to a self-signed certificate, open Certificates › Server certificate and click Revert to an automatic self-signed certificate. Clients that require a CA-signed certificate are then refused.
By default any client certificate is accepted. To accept only approved clients:
-----BEGIN X509 CRL-----). Every client certificate signed by these CAs is accepted, unless it is revoked.The client certificate is exchanged on secured channels. Combine Trusted clients only with Security modes =
SignAndEncrypt(section 2), otherwise a client can still connect on an unsecured endpoint.
Validation through CA certificates and CRLs needs a recent OPC UA library on the device. The Server certificate window shows CA / CRL validation: available, or not available with this node-opcua version. In the second case, the CA certificates and CRLs are ignored with a warning in the gateway log and only the certificates listed in Trusted client certificates (PEM) are accepted: approve each client one by one.
By default, the variables of the server are published in namespace 1: a NodeId such as ns=4;s=Boiler.Temperature is rewritten to ns=1;s=Boiler.Temperature when the gateway starts. When a client or a specification imposes a namespace index:
ns=4;s=Boiler.Temperature (see NodeId).Addresses already rewritten to ns=1 before the option was checked keep ns=1: correct their NodeId afterwards.
With UaExpert or any OPC UA client:
opc.tcp://<host name>:26543, using one of the host names of the certificate.SignAndEncrypt with the selected policies.The Certificates › Server certificate window summarises the result on the gateway side:
| Line | What to check |
|---|---|
| Issuer | The name of your CA, not self-signed. |
| Valid until | The expiry date to plan the renewal. |
| Application URI (SAN) and Announced application URI | Identical. |
| DNS names (SAN), IP addresses (SAN) | The names and addresses the clients use. |
| Trusted clients only | yes. |
| node-opcua, CA / CRL validation, Aes256_Sha256_RsaPss | What the library installed on the device supports. |
| Symptom | Cause and fix |
|---|---|
The server does not start, the log shows none of the configured server security modes is usable or ... policies is usable |
No selected mode or policy is supported by the installed library. Select SignAndEncrypt with Basic256Sha256. |
| A client finds no endpoint | Its security mode or policy is not offered any more. Configure it for SignAndEncrypt with one of the selected policies. |
| A client is refused although its account is correct | Trusted clients only is checked and its certificate is not approved: look in Certificates › Refused clients. With CA validation, check that its CA is in CA certificates (PEM), and that a CRL is imported if CRL required is checked (the log then shows client certificate refused: ... with the reason). |
| Clients refuse the server after the import of a certificate | The certificate URI differs from Application URI, or the client connects with a host name that is not in the certificate, or the CA certificate is missing from the client. Compare the lines of the Server certificate window. |
Import refused: this certificate does not match the key of the pending CSR |
The certificate was issued for another CSR. Import the certificate issued for the last CSR generated on this gateway, or generate a new CSR. |
Import refused: no pending CSR |
No CSR is waiting. Generate a CSR first, then have it signed. |
Clients refuse the connection, the log shows server certificate ... expired |
Renew the certificate (section 4.4). |
| Clients must trust the server again every year | The self-signed certificate was regenerated. Install a CA-signed certificate (section 4). |