Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
48474eb
Integrate credentials checks for service and asset levels in initiali…
mariacarmina May 7, 2025
dba3198
skip lint.
mariacarmina May 7, 2025
dcd9e43
Update ci docker logs.
mariacarmina May 7, 2025
fba187a
Fix lint.
mariacarmina May 7, 2025
5e8b77e
Added credentials check for free start compute. Use download endpoint…
mariacarmina May 8, 2025
b6212cb
log error.
mariacarmina May 8, 2025
62873e0
Check if did is provided on free start compute.
mariacarmina May 8, 2025
8a510b1
cleanup logs.
mariacarmina May 8, 2025
9d1a39c
Integrate commands for compute from policy server.
mariacarmina May 12, 2025
fd0e7ac
Fix condition in the test.
mariacarmina May 12, 2025
8a81c81
Debug result.
mariacarmina May 12, 2025
3fa443b
cleanup.
mariacarmina May 12, 2025
e5f7638
print ddo test.
mariacarmina May 12, 2025
ace914c
Updated test.
mariacarmina May 12, 2025
1547a98
cleanup function.
mariacarmina May 12, 2025
fed76d7
Merge branch 'main' into feature/credentials-check-for-compute
mariacarmina May 21, 2025
bc2ee4d
remove initialize compute command. Update initializeCompute handler.
mariacarmina May 21, 2025
cefed63
Enhance code.
mariacarmina May 21, 2025
656b69b
Define dedicated type for policy server when it comes on the handler …
mariacarmina May 22, 2025
04ae7e7
Fix type of policy server on http requests.
mariacarmina May 22, 2025
3b4c42e
Fix conflicts.
mariacarmina May 30, 2025
64fae5e
Merge branch 'main' into feature/credentials-check-for-compute
mariacarmina Jun 18, 2025
a2a9793
Fix commands usage for policy server.
mariacarmina Jun 24, 2025
60258f5
Fix conflicts.
mariacarmina Jun 25, 2025
198f0e3
Fix arguments.
mariacarmina Jun 26, 2025
4f0d41f
resolve conflicts.
mariacarmina Jul 9, 2025
5ab79f9
Fix review.
mariacarmina Jul 9, 2025
1d14e9c
Use ddo.js for DDO fields manipulation.
mariacarmina Jul 10, 2025
b142f89
Update for free start compute.
mariacarmina Jul 10, 2025
ce88067
Update datasets samples.
mariacarmina Jul 10, 2025
dae8fa7
Update branch for cli.
mariacarmina Jul 10, 2025
14e9ebd
Fix datasets samples.
mariacarmina Jul 11, 2025
e338882
Merge branch 'main' into feature/credentials-check-for-compute
mariacarmina Jul 11, 2025
5477ba2
Fix samples and ci.
mariacarmina Jul 11, 2025
c9f6910
Update ddo.js.
mariacarmina Jul 11, 2025
faa9da0
Update lock.
mariacarmina Jul 11, 2025
7e7a3d9
Updated ddo schemas version.
mariacarmina Jul 13, 2025
5ea33f6
Fix samples.
mariacarmina Jul 13, 2025
e5f2068
Add engines for test.
mariacarmina Jul 13, 2025
219e97b
Bring all tests back.
mariacarmina Jul 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
ASSET_PURGATORY_URL: 'https://raw.githubusercontent.com/oceanprotocol/list-purgatory/main/list-assets.json'
ACCOUNT_PURGATORY_URL: 'https://raw.githubusercontent.com/oceanprotocol/list-purgatory/main/list-accounts.json'
- name: docker logs
run: docker logs ocean-ocean-contracts-1 && docker logs ocean-kindcluster-1 && docker logs ocean-computetodata-1 && docker logs ocean-typesense-1
run: docker logs ocean-ocean-contracts-1 && docker logs ocean-typesense-1
if: ${{ failure() }}
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -231,7 +231,7 @@ jobs:
done

- name: docker logs
run: docker logs ocean-ocean-contracts-1 && docker logs ocean-kindcluster-1 && docker logs ocean-computetodata-1 && docker logs ocean-typesense-1
run: docker logs ocean-contracts-1 && docker logs ocean-typesense-1
if: ${{ failure() }}

- name: Checkout Ocean Node
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@libp2p/websockets": "^8.1.1",
"@multiformats/multiaddr": "^10.2.0",
"@oceanprotocol/contracts": "^2.3.0",
"@oceanprotocol/ddo-js": "^0.1.1",
"@oceanprotocol/ddo-js": "^0.1.2",
"@types/lodash.clonedeep": "^4.5.7",
"axios": "^1.8.4",
"base58-js": "^2.0.0",
Expand Down
7 changes: 5 additions & 2 deletions src/@types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UrlFileObject,
BaseFileObject
} from './fileObject'
import { PolicyServerTask } from './policyServer.js'

export interface Command {
command: string // command name
Expand Down Expand Up @@ -58,7 +59,7 @@ export interface DownloadCommand extends Command {
consumerAddress: string
signature: string
aes_encrypted_key?: string // if not present it means download without encryption
policyServer?: any // object to pass to policy server
policyServer?: PolicyServerTask // object to pass to policy server
}

export interface FileInfoCommand extends Command {
Expand Down Expand Up @@ -138,7 +139,7 @@ export interface GetFeesCommand extends Command {
serviceId: string
consumerAddress?: string
validUntil?: number // this allows a user to request a fee that is valid only for a limited period of time, less than service.timeout
policyServer?: any // object to pass to policyServer
policyServer?: PolicyServerTask // object to pass to policyServer
}
// admin commands
export interface AdminStopNodeCommand extends AdminCommand {}
Expand Down Expand Up @@ -189,6 +190,7 @@ export interface ComputeInitializeCommand extends Command {
consumerAddress: string
signature?: string
maxJobDuration: number
policyServer?: PolicyServerTask // object to pass to policy server
}

export interface FreeComputeStartCommand extends Command {
Expand All @@ -201,6 +203,7 @@ export interface FreeComputeStartCommand extends Command {
output?: ComputeOutput
resources?: ComputeResourceRequest[]
maxJobDuration?: number
policyServer?: PolicyServerTask // object to pass to policy server
metadata?: DBComputeJobMetadata
}
export interface PaidComputeStartCommand extends FreeComputeStartCommand {
Expand Down
8 changes: 8 additions & 0 deletions src/@types/policyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ export interface PolicyServerResult {
message?: string // error message, if any
httpStatus?: number // status returned by server
}

export interface PolicyServerTask {
sessionId?: string
successRedirectUri?: string
errorRedirectUri?: string
responseRedirectUri?: string
presentationDefinitionUri?: string
}
84 changes: 79 additions & 5 deletions src/components/core/compute/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import {
validateCommandParameters
} from '../../httpRoutes/validateCommands.js'
import { isAddress } from 'ethers'
import { getConfiguration } from '../../../utils/index.js'
import { getConfiguration, isPolicyServerConfigured } from '../../../utils/index.js'
import { sanitizeServiceFiles } from '../../../utils/util.js'
import { FindDdoHandler } from '../handler/ddoHandler.js'
import { isOrderingAllowedForAsset } from '../handler/downloadHandler.js'
import { getNonceAsNumber } from '../utils/nonceHandler.js'
import { C2DEngineDocker, getAlgorithmImage } from '../../c2d/compute_engine_docker.js'
import { DDOManager } from '@oceanprotocol/ddo-js'
import { Credentials, DDOManager } from '@oceanprotocol/ddo-js'
import { areKnownCredentialTypes, checkCredentials } from '../../../utils/credentials.js'
import { PolicyServer } from '../../policyServer/index.js'

export class ComputeInitializeHandler extends CommandHandler {
validate(command: ComputeInitializeCommand): ValidateParams {
Expand Down Expand Up @@ -178,11 +180,12 @@ export class ComputeInitializeHandler extends CommandHandler {

// check algo
let index = 0
const policyServer = new PolicyServer()
for (const elem of [...[task.algorithm], ...task.datasets]) {
const result: any = { validOrder: false }
if ('documentId' in elem && elem.documentId) {
result.did = elem.documentId
result.serviceId = elem.documentId
result.serviceId = elem.serviceId
const ddo = await new FindDdoHandler(node).findAndFormatDdo(elem.documentId)
if (!ddo) {
const error = `DDO ${elem.documentId} not found`
Expand All @@ -194,6 +197,12 @@ export class ComputeInitializeHandler extends CommandHandler {
}
}
}
const ddoInstance = DDOManager.getDDOClass(ddo)
const {
chainId: ddoChainId,
nftAddress,
credentials
} = ddoInstance.getDDOFields()
const isOrdable = isOrderingAllowedForAsset(ddo)
if (!isOrdable.isOrdable) {
CORE_LOGGER.error(isOrdable.reason)
Expand All @@ -205,6 +214,39 @@ export class ComputeInitializeHandler extends CommandHandler {
}
}
}
// check credentials (DDO level)
let accessGrantedDDOLevel: boolean
if (credentials) {
// if POLICY_SERVER_URL exists, then ocean-node will NOT perform any checks.
// It will just use the existing code and let PolicyServer decide.
if (isPolicyServerConfigured()) {
const response = await policyServer.checkStartCompute(
ddoInstance.getDid(),
ddo,
elem.serviceId,
task.consumerAddress,
task.policyServer
)
accessGrantedDDOLevel = response.success
} else {
accessGrantedDDOLevel = areKnownCredentialTypes(credentials as Credentials)
? checkCredentials(credentials as Credentials, task.consumerAddress)
: true
}
if (!accessGrantedDDOLevel) {
CORE_LOGGER.logMessage(
`Error: Access to asset ${ddoInstance.getDid()} was denied`,
true
)
return {
stream: null,
status: {
httpStatus: 403,
error: `Error: Access to asset ${ddoInstance.getDid()} was denied`
}
}
}
}
const service = AssetUtils.getServiceById(ddo, elem.serviceId)
if (!service) {
const error = `Cannot find service ${elem.serviceId} in DDO ${elem.documentId}`
Expand All @@ -216,9 +258,41 @@ export class ComputeInitializeHandler extends CommandHandler {
}
}
}
// check credentials on service level
// if using a policy server and we are here it means that access was granted (they are merged/assessed together)
if (service.credentials) {
let accessGrantedServiceLevel: boolean
if (isPolicyServerConfigured()) {
// we use the previous check or we do it again
// (in case there is no DDO level credentials and we only have Service level ones)
const response = await policyServer.checkStartCompute(
ddo.id,
ddo,
elem.serviceId,
task.consumerAddress,
task.policyServer
)
accessGrantedServiceLevel = accessGrantedDDOLevel || response.success
} else {
accessGrantedServiceLevel = areKnownCredentialTypes(service.credentials)
? checkCredentials(service.credentials, task.consumerAddress)
: true
}

const ddoInstance = DDOManager.getDDOClass(ddo)
const { chainId: ddoChainId, nftAddress } = ddoInstance.getDDOFields()
if (!accessGrantedServiceLevel) {
CORE_LOGGER.logMessage(
`Error: Access to service with id ${service.id} was denied`,
true
)
return {
stream: null,
status: {
httpStatus: 403,
error: `Error: Access to service with id ${service.id} was denied`
}
}
}
}
const config = await getConfiguration()
const { rpc, network, chainId, fallbackRPCs } =
config.supportedNetworks[ddoChainId]
Expand Down
Loading