IMDHMIControls LibraryShop main store

Troubleshooting

Why an OPC UA client fails on CODESYS user authentication

Industrial networks Published 9 min read By IMDHMI controls team

Short answer

An anonymous OPC UA client reaches the CODESYS endpoint and then fails: with user authentication active, the runtime rejects the anonymous token at session activation. Tick Allow anonymous login in the run-time security policy and connect to the full endpoint address on port 4840, or keep authentication on and send a matching username and password from the client.

On this page
  1. Why does discovery work but the OPC UA connection to CODESYS still fail?
  2. Which CODESYS setting rejects an anonymous OPC UA client?
  3. How do I allow anonymous login on the CODESYS runtime?
  4. What belongs in the Visual Components OPC UA connection fields?
  5. How do I prove the network path before touching authentication?
  6. When should I use a username and password instead of anonymous login?
  7. Why does the CODESYS project login prompt not belong in the OPC UA client?
  8. What should I record if the connection still fails?
  9. Questions asked

An anonymous OPC UA client fails against CODESYS at login, not at the network: the client reaches the endpoint and builds the secure channel, and the runtime then rejects the session because user authentication is enabled and the client offers no user token. In the reported case, a Visual Components Premium 4.4 OPC UA connection to a CODESYS runtime on another computer behaved exactly this way, and the change that closed it was ticking Allow anonymous login in the runtime's security policy. If your installation needs per-user accountability, keep authentication on and send a matching username and password from the client instead. The sections below separate the two failure stages, name the setting that rejects the token, show what belongs in each client field, and give the decision for each case.

Why does discovery work but the OPC UA connection to CODESYS still fail? #

Because a successful discovery response proves only that the client reached the CODESYS OPC UA server on TCP port 4840; the failure lands one step later, at ActivateSession, where the runtime checks the user identity token the client presents. Discovery and activation test different things, so a green discovery and a red connection are not contradictory.

An OPC UA connection is a sequence, and each step has its own failure mode:

  • Endpoint discovery: the client asks its discovery address for the server's endpoint description; success proves a listener answered, nothing about identity.
  • Secure channel: client and server agree a security policy (None, Sign or SignAndEncrypt) and exchange certificates if that policy needs them.
  • CreateSession: the server allocates the session and returns it to the client.
  • ActivateSession: the client presents its user identity token and the server accepts or rejects it against the token policies the endpoint advertises.

The reported case received its endpoint description, then stopped at connection initiation, which is the session stage where identity is checked. OPC UA Part 4, standardized as IEC 62541-4, puts the identity handover in clause 5.7.3, ActivateSession: the server validates the presented token against the user token policies it announced for the endpoint, and a token that matches no policy is rejected, so the connection reports failure although the network is already proven. A page on resolving OPC UA ActivateSession anonymous token failures works through the same mechanics from the client side. Treat a completed discovery as a transport result only, and move the diagnosis to identity instead of restarting the runtime or changing IP settings for a fault the login policy causes.

Which CODESYS setting rejects an anonymous OPC UA client? #

The run-time security policy of the CODESYS runtime: with user authentication active it advertises no anonymous token policy, so an anonymous client's ActivateSession request is rejected even though endpoint discovery and the secure channel succeeded. The setting, not the network, decides the outcome.

Two layers sit above the transport and they fail independently. The security policy decides how messages are protected and which certificates change hands. User authentication decides which identity the server accepts at ActivateSession: anonymous, or a username and password. With user authentication active, the CODESYS endpoint offers no token policy an anonymous client can satisfy, so the anonymous token matches nothing and activation is rejected, a mismatch that survives runtime restarts and IP changes, which is why neither of those ever fixes it.

Read what the endpoint actually advertises in the client's connection dialog before assuming anything: depending on version and security policy, the endpoint may offer fewer identity policies than expected, so confirm the policy you intend to use actually appears there before blaming the client.

How do I allow anonymous login on the CODESYS runtime? #

Open the device's communication settings in the CODESYS IDE, run change run-time security policy, and tick the checkbox named Allow anonymous login; then write and start the PLC project so the runtime reloads the policy before the client reconnects. That sequence is the whole fix for an anonymous client.

  1. Stop retrying from the client while you edit the server; every repeated failure reads the same.
  2. In the IDE, open the device entry and choose change run-time security policy.
  3. Tick the checkbox named Allow anonymous login and apply the dialog.
  4. Write and start the PLC project so the runtime reloads the policy.
  5. Reconnect from the client with the anonymous identity selected.

This is the change that closed the reported case: the anonymous client activated its session immediately afterwards. If the policy dialog itself reports an error, resolve that first, because the change is applied over the connection to the runtime; check that the gateway and device address in the communication settings actually reach the running runtime, then repeat the edit.

One boundary belongs here: with anonymous login allowed, any host that can open the OPC UA port on the runtime can read and write the exposed variables, so use this on an isolated bench or machine network and keep user authentication enabled wherever the network carries hosts you cannot vouch for.

What belongs in the Visual Components OPC UA connection fields? #

The discovery field takes the local machine's discovery address only when that discovery server runs on the client's own computer; the server address must be the CODESYS endpoint itself, opc.tcp://192.168.0.15:4840 in this case, with the identity left anonymous. Those two fields answer different questions and must not copy each other.

localhost always resolves to the machine the client process runs on. The tutorial followed in the reported case put opc.tcp://localhost:4840 in the discovery field, which works when the discovery server and the client share one computer; run the client on a separate PC and that field silently lists the client's own machine instead of the runtime. The server address is the field that must carry the runtime's endpoint, its address and its port together, exactly as the runtime advertises them. The scheme matters too: opc.tcp is the binary OPC UA transport used here, while opc.https and opc.wss belong to web and websocket stacks, and a page decoding OPC UA endpoint URLs, opc.tcp, opc.https and opc.wss explains when each scheme appears. Leave the identity set to anonymous so it matches the policy configured on the runtime; an identity the server does not offer reproduces the original rejection even with the address correct.

How do I prove the network path before touching authentication? #

Test TCP port 4840 on the runtime's address from the client PC before changing any policy: a successful connection attempt to 192.168.0.15 on port 4840 proves the listener, the firewall and the route, so whatever fails afterwards is not the network. That single test splits the fault list in two.

Worked example of the same-subnet check, with an example client address. Say the client PC runs at 192.168.0.20 with subnet mask 255.255.255.0, and the runtime sits at 192.168.0.15. AND each address with the mask: 192.168.0.20 AND 255.255.255.0 gives 192.168.0.0, and 192.168.0.15 AND 255.255.255.0 gives 192.168.0.0. Equal network addresses mean both hosts share one subnet, so the TCP attempt to the runtime's endpoint travels the local segment with no router involved; a timeout then indicts the listener, the runtime's interface binding or a host firewall, in that order. Move the client to 192.168.1.20 and the first AND yields 192.168.1.0, different from 192.168.0.0, so a router enters the path and its rules join the fault list, which is how a clean ping can still hide a routed path the runtime's endpoint never sees.

If the TCP attempt fails while the subnet arithmetic is clean, check which interface the runtime's OPC UA server listens on: the runtime configuration file CODESYSControl_User.cfg holds the OPC UA server parameters, and restricting the server to one network card is a known adjustment when the host carries several interfaces. A page on troubleshooting opc.tcp endpoint initialization failures lists the listener-side causes in the same order, from service state through binding to firewall.

When should I use a username and password instead of anonymous login? #

Whenever the machine network carries hosts you cannot vouch for, keep user authentication enabled, create an OPC UA user in the runtime's user management, and select the username and password identity in the client with those exact credentials. The decision is exposure, not convenience.

The two ends must agree: an anonymous client against a server that demands credentials fails exactly like this case, and a credentialed client against a server offering only anonymous access fails with its own rejection. A bench or an isolated cell where every host on the segment is accounted for: anonymous login on, client anonymous, the combination that closed the reported case. A runtime reachable from an office or plant backbone, or anywhere reads and writes affect production: user authentication stays on, an OPC UA user is created in the runtime's user management, and the client selects the username and password identity with those exact credentials. Both ends must name the same identity type, and that type must actually appear among the token policies the endpoint advertises.

Why does the CODESYS project login prompt not belong in the OPC UA client? #

Because that prompt at project start is the engineering and runtime login for downloading and running the project, not the OPC UA session identity; typing those credentials into the client does nothing unless the same account exists in the runtime's user management with OPC UA access. Two credential scopes, two separate checks.

The question came up directly in the reported case, and the answer decided it: the username and password the IDE asks for every time the PLC project starts guard engineering access, while the OPC UA session presents its own identity at ActivateSession. Configure the account the client should use in the runtime's user management, and treat the vendor documentation for the installed runtime as the authority on what that account may do. Meanwhile, restarting the project, retyping the startup password or changing addresses never touches the policy that rejected the anonymous token.

What should I record if the connection still fails? #

Capture the full client diagnostic before changing anything else: the exact message text, the endpoint URL attempted, the security policy selected and the identity type offered, because a policy or certificate rejection at the secure channel stage produces a different fix than an identity rejection. Four facts sort every remaining case.

In the reported case no exact error text was available; the screen showed a failed connection initiation after a successful discovery. With the four facts in hand, sort by layer. A message about security policies or untrusted certificates means the secure channel stage failed, and that layer comes first: the same fault shape on a different controller is walked through in troubleshooting an S7-1500 OPC UA client that cannot connect, and trusting the OPC UA client certificate on a B&R PLC covers the certificate side. A message about a missing or rejected token policy points at the identity stage, and the fix is the policy change described above: anonymous client to anonymous login allowed, or credentials on the client to a real user on the runtime.

Once the session activates, prove the whole path: browse the namespace, read a variable known to change, and force a change from the PLC program to watch it arrive. If reads stay good and a write fails afterwards, that is a different fault again, server-side write handling rather than this login, and why OPC UA writes fail while reads stay good picks it up from there.

Decision for each case. Simulation or bench on an isolated network: tick Allow anonymous login in the run-time security policy, connect anonymously to the runtime's own endpoint address, and the session activates, which is the reported fix. Production or any shared network: user authentication stays on, create the OPC UA user, send those exact credentials from the client, and confirm the endpoint advertises a matching token policy before blaming the client.

Questions asked

What error messages do other OPC UA clients show for this same failure?

The same server-side fault appears with different wording in different clients. Ignition reports a connection faulted with the text no anonymous token policy found, and the FUXA web client against CODESYS 3.5.21 reports that it cannot find the ANONYMOUS/USERNAME user token policy. All of them mean the same thing: the server advertises no user token policy matching the identity the client offered, so fix the server policy or the client identity.

Does the Visual Components OPC UA client connect through the CODESYS gateway?

No. The gateway carries the IDE's own traffic: project download, the login prompt at project start, and the run-time security policy dialog. An OPC UA client connects directly to the runtime's endpoint address on its OPC UA port, so gateway settings never appear in the client connection and never explain a session that completes discovery but fails activation.

Can an anonymous client and a credentialed client connect to the same CODESYS server at once?

Yes, as long as the endpoint advertises both token policies. With anonymous login allowed, the server accepts an anonymous session and, side by side, a session that carries a valid username and password. If you later switch anonymous login off, the anonymous client starts failing at ActivateSession again while the credentialed client keeps working, which is a clean way to prove which identity each connection actually uses.

Which combinations of security policy and user identity are sensible?

Security policy and user identity are separate choices. A bench or isolated cell commonly runs the None policy with anonymous login allowed, which is the combination that closed the reported case. A shared network deserves Sign or SignAndEncrypt with exchanged certificates and a username and password at ActivateSession. Fixing a certificate problem never repairs a rejected user token, and the reverse, so diagnose the layers separately, in connection order.

Keep reading

  • How-to

    CODESYS as an OPC UA client to an S7-1200 server

    Yes: a CODESYS runtime can act as an OPC UA client to an S7-1200 acting as the server, but only with the separately licensed OPC UA Client SL on the CODESYS device, an S7-1200 CPU and firmware that support its OPC UA server with published variables, and a matching endpoint, exchanged application certificates, an authorized user identity and the variable's NodeId. Configuring the S7-1200 server alone provides none of that.

    Industrial networks

  • Troubleshooting

    Connecting Factory I/O to a local CODESYS soft PLC over OPC UA

    Yes: OPC UA only carries tag values, so the ladder or structured text must run in the CODESYS runtime. Fix the connection in order: prove the engineering path through the Gateway to the runtime first, then the OPC UA endpoint at port 4840, then map each scene point to one variable. Keep Control I/O out of it, because Factory I/O runs one driver at a time.

    Industrial networks

  • How-to

    Connecting a CODESYS HMI on Windows to an S7-1500 PLC

    Yes, it works. Use OPC UA with the S7-1500 as server and the CODESYS HMI as client when the PC only supervises; use a CODESYS Control Win runtime with target visualization over a PROFINET controller/device link when the PC must also run logic. The PROFINET path adds one single-device license on top of the runtime; the OPC UA path adds none.

    SCADA and data logging