awcullen / opcua

OPC Unified Architecture (OPC UA) in Go.
MIT License
81 stars 18 forks source link

Opcua server authentication issue #5

Closed rickpatx-code closed 2 years ago

rickpatx-code commented 2 years ago

Hello, I have a problem when i want to write a value with anonymous authentication settings. I have read access to my server but when i want to override a value i get a BadUserAccessDenied error.

My server looks like this:

 srv, err := server.New(
        ua.ApplicationDescription{
            ApplicationURI: fmt.Sprintf("urn:%s:testserver", host),
            ProductURI:     "http://github.com/awcullen/opcua",
            ApplicationName: ua.LocalizedText{
                Text:   fmt.Sprintf("testserver@%s", host),
                Locale: "en",
            },
            ApplicationType:     ua.ApplicationTypeServer,
            GatewayServerURI:    "",
            DiscoveryProfileURI: "",
            DiscoveryURLs:       []string{endpointURL},
        },
        "./pki/server.crt",
        "./pki/server.key",
        endpointURL,
        server.WithBuildInfo(
            ua.BuildInfo{
                ProductURI:       "http://github.com/awcullen/opcua",
                ManufacturerName: "awcullen",
                ProductName:      "testserver",
                SoftwareVersion:  SoftwareVersion,
            }),
        server.WithInsecureSkipVerify(),
        server.WithAnonymousIdentity(true),
        server.WithSecurityPolicyNone(true),
    )
awcullen commented 2 years ago

Great question. It seems like the easiest way is to add another option like

server.WithRolePermissions([]ua.RolePermissionType{
    {RoleID: ua.ObjectIDWellKnownRoleAnonymous, Permissions: (ua.PermissionTypeBrowse | ua.PermissionTypeRead | ua.PermissionTypeWrite | ua.PermissionTypeReadHistory | ua.PermissionTypeReceiveEvents | ua.PermissionTypeCall)},
    {RoleID: ua.ObjectIDWellKnownRoleAuthenticatedUser, Permissions: (ua.PermissionTypeBrowse | ua.PermissionTypeRead | ua.PermissionTypeWrite | ua.PermissionTypeReadHistory | ua.PermissionTypeReceiveEvents | ua.PermissionTypeCall)},
}),