American units being segregated is quite well-known, but how would a black or Asian man signing up to the British, Canadian or ANZAC forces be treated? Were there all-black divisions, or would they serve with white soldiers? Could they serve in combat roles?
I can't speak for the Canadian, Australian or South African armed forces, but I can comment on the case in the British Army during the Second World War.
Firstly, I'll hold my hands up and say I do not have immediate access to the primary sources which I would usually use to answer a question like this (thanks COVID). But, the two main documents which lay out the letter of the law as it pertains to the British Army during the period you're interested in are, The Manual of Military Law (MML) and King's Regulations for the Army (KRs). Both of these documents were regularly amended, updated and re-published, so it is incredibly difficult to even work out which specific version of these documents were in force on a given date. But, the following answer should give you a broad-brush to understand the issue of race in the British Army during the Second World War.
The first thing that needs to be explained is that, in this period, it is not quite as simple as talking about "the British Army". Put simply, the British Army as we would understand it today existed as three separate entities during the first half of the 20th century. This is primarily down to Britain's role as a global, colonial superpower during the period, but also because these institutions were not purpose-built from the ground up, but developed over time. The three entities were: the British Army, the Indian Army, and the Colonial Forces. Together, these would be grouped together as the "Forces of the Crown", which, in short-hand, could be described as "the British Army", if by that you mean the totality of the land forces available for use by the British government. Each of these entities were legally separate, and the terms of their organisation and the legal liabilities of those serving within them were dealt with separately in both MML and KRs.
We then get into the idea of race as it was understood in these two documents, and therefore by the War Office, British Army and British military law as a whole. In broad terms, a distinction is made between personnel of "European descent" (wording as per MML 1914 and later versions) and personnel who are not of European descent. It's helpful to think of this as short-hand for what we'd call "white British" today. There is then the obvious divide between officers and other ranks, with different legal obligations applying to each depending on their status but also depending on whether they are of European descent or not.
The main complicating factors in this are the Indian and Colonial forces. The Indian forces were controlled (and paid for) by the government of India, and were under the provisions of a separate Army Act to the British forces. The Indian forces were primarily made up of Indian natives, commanded by officers of European descent. There were also personnel of various mixtures of European and native Indian ancestry serving, who were, depending on the specifics of their ancestry, their rank, where or how their unit was serving and the specifics of the legal situation, treated as either European or native. This cut both ways. Under the provisions of the 1914 MML, it was prohibited for Europeans to enlist in the Indian forces except as medical specialists or similar. It was also prohibted for "European forces" (wording as per MML 1914) to be enlisted for service in India alone.
Alongside the Indian Army (Indian regiments, raised in India, primarily composed of Indian natives and commanded by British officers), there was the British Indian Army. These were the British units - recruited in Britain, with British officers and other ranks - which were formally part of the British forces and which were deployed to India to serve in garrisons and formations alongside the Indian Army. There was a specific ratio of British to Indian units, and there would usually be a single British battalion in each Indian brigade. These personnel were under British (not Indian) military law.
The Colonial forces were the armed forces of Britain's remaining colonial possessions. This was a huge patchwork of different entities, and each would have been formally paid for by, and under the control of, the colony's government, albeit with firm oversight from the British government, in particular the Treasury, the Colonial Office and the War Office. I can find less concrete legal information on the Colonial forces in the documents I can access, but that says as much about how hugely complex the issue is as it does the documents I have access to. But, as with the Indian forces, a distinction is made between European (British) and native as well as officers and other ranks.
Now, onto your actual question. From what I have seen, there is nothing written in either the MML or KRs which would prohibit an individual from service in the British Army because of their ethnic background. There may be restrictions on where and how they can serve, for example if they were an Indian native then they would be legally obliged to serve in the Indian forces and would be unlikely to be able to enlist as an officer, attend Sandhurst and be given a commission in the British Army. But, by the same token, it would be incredibly unlikely for someone who is affluent, white and British to end up serving as a private in an Indian battalion. Bluntly, this all gets very muddy, and the specific status of individuals is as much down to the luck and circumstance as the letter of the law.
In terms of formal segregation or limiting certain troops to certain duties, this did not happen except as I have described above. There were plenty of divisions, brigades and units composed of all different ethnic groups, and units of all ethnic groups which performed a wide range of military tasks. There were several divisions formed from Britain's East and West African troops, which were essentially organised as African versions of Indian formations, and included British and native combat units as well as associated support elements from both backgrounds, with the native units commanded by British officers. There were West Indian infantry battalions, and a huge range of Indian armoured, infantry, artillery, engineer and even paratroop units; these would have served in Indian divisions and brigades, alongside British units from the British Indian Army and also alongside all-British formations like the British 2nd Infantry Division.
In terms of non-white personnel serving in the British forces - that is, the formations and units composed of personnel recruited from within Britain itself - again there was nothing which would legally prohibit it as far as I have seen. The limiting factor would be the number of people who were from an ethnic minority and resident in Britain at the time. This number would be far lower than today, and this is reflected in the fact that the overwhelming majority of ethnic minority personnel who served in the Forces of the Crown during the Second World War did so as members of either the Indian or Colonial forces because they were not born or in Britain or residents of the UK during the war.